Skip to content

Commit

Permalink
support orientation changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Adar Porat committed Sep 1, 2020
1 parent 67b9b8b commit 2d54e7e
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions KKProgressToolbar/KKProgressToolbar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public protocol KKProgressToolbarDelegate: class {
public final class KKProgressToolbar: UIView {

fileprivate var didSetupConstraints = false

// MARK: - Data
fileprivate let orientationDidChange = UIDevice.orientationDidChangeNotification

weak public var actionDelegate: KKProgressToolbarDelegate?
public var isShown = false

Expand Down Expand Up @@ -75,6 +75,10 @@ public final class KKProgressToolbar: UIView {
setupSubviews()
}

deinit {
NotificationCenter.default.removeObserver(self)
}

override public func updateConstraints() {
super.updateConstraints()

Expand Down Expand Up @@ -108,13 +112,26 @@ public final class KKProgressToolbar: UIView {
}

fileprivate func setupSubviews() {
NotificationCenter.default.addObserver(self, selector: #selector(setupPosition), name: orientationDidChange, object: nil)

addSubview(mainBackgroundView)
addSubview(stopButton)
addSubview(titleLabel)
addSubview(progressBar)

setNeedsUpdateConstraints()
}

@objc fileprivate func setupPosition() {
if self.isShown {
self.hide(false) {
self.isHidden = false
self.show(false)
}
} else {
self.setNeedsLayout()
}
}

public func show(_ animated: Bool, completion: (() -> Void)? = nil) {
if !isShown {
Expand Down

0 comments on commit 2d54e7e

Please sign in to comment.