From dee700fbea4649f9bb838c489b2b3fc1035a16df Mon Sep 17 00:00:00 2001 From: Grigory Ulanov Date: Sun, 30 Oct 2016 01:03:51 +0300 Subject: [PATCH] status bar --- SKPhotoBrowser/SKNavigationBar.swift | 2 +- SKPhotoBrowser/SKPhotoBrowser.swift | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/SKPhotoBrowser/SKNavigationBar.swift b/SKPhotoBrowser/SKNavigationBar.swift index 9457df3..a129ed3 100644 --- a/SKPhotoBrowser/SKNavigationBar.swift +++ b/SKPhotoBrowser/SKNavigationBar.swift @@ -67,7 +67,7 @@ class SKNavigationBar: UIView { override func layoutSubviews() { if UIDevice.current.orientation == .portrait { countLabel?.frame = CGRect(x: 0, y: statusBarHeight, width: bounds.width, height: bounds.height) - doneButton?.frame = CGRect(x: 0, y: statusBarHeight, width: 85, height: bounds.height) + doneButton?.frame = CGRect(x: 0, y: statusBarHeight, width: 85, height: bounds.height - statusBarHeight) } else { countLabel?.frame = bounds doneButton?.frame = CGRect(x: 0, y: 0, width: 85, height: bounds.height) diff --git a/SKPhotoBrowser/SKPhotoBrowser.swift b/SKPhotoBrowser/SKPhotoBrowser.swift index 708902c..907d5db 100644 --- a/SKPhotoBrowser/SKPhotoBrowser.swift +++ b/SKPhotoBrowser/SKPhotoBrowser.swift @@ -31,6 +31,13 @@ open class SKPhotoBrowser: UIViewController { var initialPageIndex: Int = 0 var currentPageIndex: Int = 0 + + // status bar + fileprivate var isStatusBarHidden = false { + didSet { + setNeedsStatusBarAppearanceUpdate() + } + } // for status check property fileprivate var isEndAnimationByToolBar: Bool = true @@ -135,6 +142,8 @@ open class SKPhotoBrowser: UIViewController { open override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() + isStatusBarHidden = UIDevice.current.orientation != .portrait + isPerformingLayout = true closeButton.updateFrame() @@ -154,7 +163,7 @@ open class SKPhotoBrowser: UIViewController { super.viewDidAppear(true) isViewActive = true - setNeedsStatusBarAppearanceUpdate() + isStatusBarHidden = false } open override var preferredStatusBarStyle: UIStatusBarStyle { @@ -445,7 +454,7 @@ internal extension SKPhotoBrowser { firstY = zoomingScrollView.center.y hideControls() - setNeedsStatusBarAppearanceUpdate() + isStatusBarHidden = true } translatedPoint = CGPoint(x: firstX, y: firstY + translatedPoint.y) @@ -457,10 +466,6 @@ internal extension SKPhotoBrowser { : -(zoomingScrollView.center.y - viewHalfHeight)) / viewHalfHeight view.alpha = CGFloat.maximum(0.6, offset) - - if sender.state == .began { - setNeedsStatusBarAppearanceUpdate() - } // gesture end if sender.state == .ended || sender.state == .cancelled || sender.state == .failed { @@ -480,7 +485,7 @@ internal extension SKPhotoBrowser { } else { // Continue Showing View - setNeedsStatusBarAppearanceUpdate() + isStatusBarHidden = false let velocityY: CGFloat = CGFloat(0.35) * sender.velocity(in: self.view).y let finalX: CGFloat = firstX @@ -628,7 +633,8 @@ private extension SKPhotoBrowser { if !permanent { hideControlsAfterDelay() } - setNeedsStatusBarAppearanceUpdate() + + isStatusBarHidden = hidden } func deleteImage() {