From 394b9f1fb82536b11f9fc0e7344cae9fd46e7c25 Mon Sep 17 00:00:00 2001 From: Kawoou Date: Fri, 16 Jun 2017 22:38:58 +0900 Subject: [PATCH 1/2] Fix layout issue! --- DrawerController/DrawerController.swift | 80 +++++++++++++++++-------- 1 file changed, 54 insertions(+), 26 deletions(-) diff --git a/DrawerController/DrawerController.swift b/DrawerController/DrawerController.swift index 83cc7d5..ec65f63 100644 --- a/DrawerController/DrawerController.swift +++ b/DrawerController/DrawerController.swift @@ -137,6 +137,8 @@ open class DrawerController: UIViewController, UIGestureRecognizerDelegate { private var tapGestureRecognizer: UITapGestureRecognizer? + private var currentOrientation: UIDeviceOrientation = .unknown + /// Gesture private var gestureBeginPoint: CGPoint = CGPoint.zero private var gestureMovePoint: CGPoint = CGPoint.zero @@ -769,6 +771,39 @@ open class DrawerController: UIViewController, UIGestureRecognizerDelegate { self.delegate?.drawerDidCancelAnimation?(drawerController: self, side: side) } + private func updateLayout() { + + for (_, content) in self.contentMap { + content.updateView() + } + + if !self.isAnimating { + for (side, content) in self.contentMap { + if side == .none { continue } + + let percent: Float = self.drawerSide == .none ? 0.0 : 1.0 + + self.willBeginAnimate(side: self.drawerSide) + self.didBeginAnimate(side: self.drawerSide) + self.willAnimate(side: self.drawerSide, percent: percent) + self.didAnimate(side: self.drawerSide, percent: percent) + + content.startTransition(side: self.drawerSide) + content.transition( + side: self.drawerSide, + percentage: self.calcPercentage(side: side, moveSide: self.drawerSide, percent), + viewRect: self.calcViewRect(content: content) + ) + content.endTransition(side: self.drawerSide) + + self.willFinishAnimate(side: self.drawerSide, percent: percent) + self.didFinishAnimate(side: self.drawerSide, percent: percent) + + } + } + + } + // MARK: - UIGestureRecognizerDelegate @@ -1110,38 +1145,31 @@ open class DrawerController: UIViewController, UIGestureRecognizerDelegate { if let rightSegueID = self.rightSegueIdentifier { self.performSegue(withIdentifier: rightSegueID, sender: self) } + + /// Events + self.view.addObserver(self, forKeyPath: "center", options: .new, context: nil) + } + + deinit { + self.view.removeObserver(self, forKeyPath:"center") } open override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() - for (_, content) in self.contentMap { - content.updateView() - } + let newOrientation = UIDevice.current.orientation + guard newOrientation != .unknown else { return } + guard newOrientation != self.currentOrientation else { return } + self.currentOrientation = newOrientation - if !self.isAnimating { - for (side, content) in self.contentMap { - if side == .none { continue } - - let percent: Float = self.drawerSide == .none ? 0.0 : 1.0 - - self.willBeginAnimate(side: self.drawerSide) - self.didBeginAnimate(side: self.drawerSide) - self.willAnimate(side: self.drawerSide, percent: percent) - self.didAnimate(side: self.drawerSide, percent: percent) - - content.startTransition(side: self.drawerSide) - content.transition( - side: self.drawerSide, - percentage: self.calcPercentage(side: side, moveSide: self.drawerSide, percent), - viewRect: self.calcViewRect(content: content) - ) - content.endTransition(side: self.drawerSide) - - self.willFinishAnimate(side: self.drawerSide, percent: percent) - self.didFinishAnimate(side: self.drawerSide, percent: percent) - - } + self.updateLayout() + } + + open override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { + super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context) + + if keyPath == "center" { + self.updateLayout() } } From 99736579c65f3dee5fa2590405f057332a22889d Mon Sep 17 00:00:00 2001 From: Kawoou Date: Fri, 16 Jun 2017 22:39:42 +0900 Subject: [PATCH 2/2] Update podspec. --- KWDrawerController.podspec | 2 +- README.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/KWDrawerController.podspec b/KWDrawerController.podspec index 82f7d2a..c2b99c1 100644 --- a/KWDrawerController.podspec +++ b/KWDrawerController.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "KWDrawerController" - s.version = "3.6" + s.version = "3.6.1" s.summary = "Drawer view controller that easy to use!" s.license = { :type => "MIT", :file => "LICENSE" } s.homepage = "https://github.com/Kawoou/KWDrawerController" diff --git a/README.md b/README.md index 7c20292..b65671a 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ KWDrawerController ================== -[![Pod Version](http://img.shields.io/cocoapods/v/KWDrawerController.svg?style=flat)](http://cocoadocs.org/docsets/KWDrawerController/3.6) -[![Pod Platform](http://img.shields.io/cocoapods/p/KWDrawerController.svg?style=flat)](http://cocoadocs.org/docsets/KWDrawerController/3.6) +[![Pod Version](http://img.shields.io/cocoapods/v/KWDrawerController.svg?style=flat)](http://cocoadocs.org/docsets/KWDrawerController/3.6.1) +[![Pod Platform](http://img.shields.io/cocoapods/p/KWDrawerController.svg?style=flat)](http://cocoadocs.org/docsets/KWDrawerController/3.6.1) [![Pod License](http://img.shields.io/cocoapods/l/KWDrawerController.svg?style=flat)](https://github.com/kawoou/KWDrawerController/blob/master/LICENSE) ![Swift](https://img.shields.io/badge/Swift-3.0-orange.svg) @@ -17,7 +17,7 @@ Installation KWDrawerController is available on [CocoaPods](https://github.com/cocoapods/cocoapods). Add the following to your Podfile: ```ruby -pod 'KWDrawerController', '~> 3.6' +pod 'KWDrawerController', '~> 3.6.1' ```