Commit 35008f53 by Dmitriy Stepanets

Finished legend layout

parent d35e906a
......@@ -31,7 +31,7 @@ class MapLegendSevereView: UIView {
private func prepare() {
stackView.axis = .horizontal
stackView.spacing = 4
stackView.spacing = 8
stackView.distribution = .equalSpacing
addSubview(stackView)
......@@ -66,7 +66,7 @@ private class SevereLegendElement:UIView {
private func prepare() {
self.snp.makeConstraints { (make) in
make.width.equalTo(50)
make.width.equalTo(50).priority(999)
}
imageView.clipsToBounds = true
......@@ -75,7 +75,7 @@ private class SevereLegendElement:UIView {
addSubview(imageView)
imageView.snp.makeConstraints { (make) in
make.top.equalToSuperview().inset(3)
make.top.equalToSuperview().inset(3).priority(999)
make.width.equalTo(30)
make.height.equalTo(10)
make.centerX.equalToSuperview()
......
......@@ -15,7 +15,6 @@ private enum LegendType {
class MapLegendView: UIView {
//Private
private let kOpenWidth:CGFloat = 180
private let kCloseWidth:CGFloat = 40
private let containerView = UIView()
private let button = UIButton()
......@@ -34,8 +33,12 @@ class MapLegendView: UIView {
prepareView()
prepareViewGradient()
prepareButton()
prepareContainer()
prepareLegend()
updateUI()
containerView.setNeedsLayout()
containerView.layoutIfNeeded()
}
required init?(coder: NSCoder) {
......@@ -59,6 +62,8 @@ class MapLegendView: UIView {
public func configure(radarLayer:RadarLayer) {
legendSevereView.alpha = 0
legendWeatherView.alpha = 0
legendSevereView.snp.removeConstraints()
legendWeatherView.snp.removeConstraints()
if let weatherLayer = radarLayer.layer as? WeatherLayerType {
self.configure(weatherLayer: weatherLayer)
......@@ -75,6 +80,7 @@ class MapLegendView: UIView {
legendWeatherView.alpha = isOpened ? 1 : 0
buttonGradient.colors = weatherLayer.colors
legendWeatherView.configure(weatherLayer: weatherLayer)
rebuildWeatherConstraints()
}
private func configure(severeLayer:SevereLayerType) {
......@@ -82,6 +88,7 @@ class MapLegendView: UIView {
legendSevereView.alpha = isOpened ? 1 : 0
buttonGradient.colors = severeLayer.colors
legendSevereView.configure(severeLayer: severeLayer)
rebuildSevereConstraints()
}
private func updateUI() {
......@@ -95,11 +102,28 @@ class MapLegendView: UIView {
}
}
private func rebuildSevereConstraints() {
legendSevereView.snp.makeConstraints { (make) in
make.left.top.bottom.equalToSuperview()
make.right.equalToSuperview().priority(.medium)
}
}
private func rebuildWeatherConstraints() {
legendWeatherView.snp.makeConstraints { (make) in
make.left.equalToSuperview()
make.right.equalToSuperview().priority(.medium)
make.top.equalToSuperview().inset(13)
make.bottom.equalToSuperview().inset(6)
}
}
@objc private func handleButton() {
if self.isOpened {
self.isOpened = false
self.widthConstraint?.isActive = true
self.heightConstraint?.isActive = true
}
else {
self.isOpened = true
......@@ -107,10 +131,12 @@ class MapLegendView: UIView {
self.heightConstraint?.isActive = false
}
self.containerView.setNeedsLayout()
self.setNeedsLayout()
self.button.setImage(isOpened ? UIImage(named: "map_legend_close") : nil, for: .normal)
UIView.animate(withDuration: 0.3) {
self.superview?.layoutIfNeeded()
self.layoutIfNeeded()
switch self.legendType {
case .weather:
self.legendWeatherView.alpha = self.isOpened ? 1 : 0
......@@ -132,10 +158,9 @@ private extension MapLegendView {
layer.shadowOpacity = 1
layer.shadowRadius = 5
addSubview(containerView)
containerView.snp.makeConstraints { (make) in
make.left.top.bottom.equalToSuperview()
self.widthConstraint = make.width.equalTo(kCloseWidth).priority(1000).constraint
self.snp.makeConstraints { (make) in
self.widthConstraint = make.width.equalTo(kCloseWidth).constraint
self.heightConstraint = make.height.equalTo(kCloseWidth).constraint
}
}
......@@ -154,7 +179,7 @@ private extension MapLegendView {
button.layer.cornerRadius = 14
button.addTarget(self, action: #selector(handleButton), for: .touchUpInside)
button.layer.insertSublayer(buttonGradient, below: button.imageView?.layer)
containerView.addSubview(button)
addSubview(button)
button.snp.makeConstraints { (make) in
make.width.height.equalTo(28)
......@@ -163,24 +188,25 @@ private extension MapLegendView {
}
}
func prepareLegend() {
legendWeatherView.alpha = 0
containerView.addSubview(legendWeatherView)
func prepareContainer() {
containerView.backgroundColor = .clear
containerView.clipsToBounds = true
addSubview(containerView)
legendWeatherView.snp.makeConstraints { (make) in
containerView.snp.makeConstraints { (make) in
make.left.equalTo(button.snp.right).offset(6).priority(999)
make.right.equalToSuperview().inset(17)
make.top.equalToSuperview().inset(13)
make.bottom.equalToSuperview().inset(6)
make.right.equalToSuperview().inset(16)
make.top.bottom.equalToSuperview()
}
}
func prepareLegend() {
legendWeatherView.alpha = 0
legendWeatherView.translatesAutoresizingMaskIntoConstraints = false
containerView.addSubview(legendWeatherView)
legendSevereView.alpha = 0
legendSevereView.translatesAutoresizingMaskIntoConstraints = false
containerView.addSubview(legendSevereView)
legendSevereView.snp.makeConstraints { (make) in
make.left.equalTo(button.snp.right).offset(6).priority(999)
make.right.equalToSuperview().inset(17)
make.top.bottom.equalToSuperview()
}
}
}
......@@ -64,19 +64,19 @@ private extension MapLegendWeatherView {
legendGradient.snp.makeConstraints { (make) in
make.left.right.top.equalToSuperview()
make.height.equalTo(4)
make.height.equalTo(4).priority(999)
}
}
func prepareStackView() {
legendLabelsStackView.axis = .horizontal
legendLabelsStackView.spacing = 4
legendLabelsStackView.distribution = .equalSpacing
legendLabelsStackView.spacing = 8
legendLabelsStackView.distribution = .fill
addSubview(legendLabelsStackView)
legendLabelsStackView.snp.makeConstraints { (make) in
make.left.right.equalToSuperview()
make.top.equalTo(legendGradient.snp.bottom).offset(6)
make.top.equalTo(legendGradient.snp.bottom).offset(6).priority(999)
make.bottom.equalToSuperview().inset(4)
}
}
......
......@@ -194,6 +194,7 @@ private extension RadarViewController {
//Legend
view.addSubview(legendView)
legendView.snp.makeConstraints { (make) in
make.width.lessThanOrEqualToSuperview()
make.right.equalToSuperview().inset(8)
make.bottom.equalTo(locationButton.snp.top).offset(-18)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment