Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
kawoou committed Feb 7, 2018
2 parents 8c18b58 + 90f0bdc commit a0a2b8e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
39 changes: 33 additions & 6 deletions DrawerController/DrawerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,13 @@ open class DrawerController: UIViewController, UIGestureRecognizerDelegate {

private var currentOrientation: UIDeviceOrientation = .unknown

#if swift(>=3.2)
private var observeContext: NSKeyValueObservation?
#else
private var isObserveKVO: Bool = false
private static var observeContext: Int = 0
#endif

/// Gesture
private var gestureBeginPoint: CGPoint = CGPoint.zero
private var gestureMovePoint: CGPoint = CGPoint.zero
Expand Down Expand Up @@ -1136,11 +1143,25 @@ open class DrawerController: UIViewController, UIGestureRecognizerDelegate {
}

/// Events
view.addObserver(self, forKeyPath: "center", options: .new, context: nil)
#if swift(>=3.2)
observeContext = view.observe(\.frame) { [weak self] (view, event) in
self?.updateLayout()
}
#else
view.addObserver(self, forKeyPath: "frame", options: .new, context: &DrawerController.observeContext)
isObserveKVO = true
#endif
}

deinit {
view.removeObserver(self, forKeyPath:"center")
#if swift(>=3.2)
observeContext?.invalidate()
observeContext = nil
#else
if isObserveKVO {
view.removeObserver(self, forKeyPath:"frame")
}
#endif
}

open override func viewDidLayoutSubviews() {
Expand All @@ -1160,14 +1181,20 @@ open class DrawerController: UIViewController, UIGestureRecognizerDelegate {
updateLayout()
}

#if !swift(>=3.2)
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" {
guard context == &DrawerController.observeContext else {
observeValue(forKeyPath: keyPath, of: object, change: change, context: context)
return
}
guard isObserveKVO else { return }

if keyPath == "frame" {
updateLayout()
}
}

#endif

public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
Expand Down
2 changes: 1 addition & 1 deletion KWDrawerController.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = 'KWDrawerController'
s.version = '4.1.2'
s.version = '4.1.3'
s.summary = 'Drawer view controller that easy to use!'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.homepage = 'https://github.com/kawoou/KWDrawerController'
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ KWDrawerController is available on [CocoaPods](https://github.com/cocoapods/coco
pod 'KWDrawerController', '~> 3.7'

# Swift 4
pod 'KWDrawerController', '~> 4.1.2'
pod 'KWDrawerController', '~> 4.1.3'
pod 'KWDrawerController/RxSwift' # with RxSwift extension
```

Expand Down Expand Up @@ -244,6 +244,8 @@ Changelog
- Replace naming.
- Implement `getViewController` method.
- Reduce cloning size.
+ 4.1.3
- [#12] Fix crashed on load.

⚠️ Requirements
--------------
Expand Down

0 comments on commit a0a2b8e

Please sign in to comment.