Skip to content

Commit

Permalink
add property shouldRequireFailureOfNavigationPopGesture
Browse files Browse the repository at this point in the history
  • Loading branch information
superk589 committed Feb 2, 2017
1 parent a668360 commit a07a085
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 16 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ drawerController.shadowWidth = 5
drawerController.gestureRecognizerWidth = 40
```

### should require failure of navigation pop gesture, default true (if setting false, showing left drawer gesture will have higher priority)
```swift
drawerController.shouldRequireFailureOfNavigationPopGesture = true
```

### set the side or main controller dynamically
```swift
// set or replace
Expand Down
2 changes: 1 addition & 1 deletion ZKDrawerController.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "ZKDrawerController"
s.version = "0.0.8"
s.version = "0.0.9"
s.summary = "An iOS drawer controller in swift."
s.description = <<-DESC
A light-weighted iOS drawer controller in swift.
Expand Down
2 changes: 1 addition & 1 deletion ZKDrawerController/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
let left = UIViewController()
left.view.backgroundColor = UIColor.clear

let drawer = ZKDrawerController.init(main: nav, right: right)
let drawer = ZKDrawerController.init(main: nav, left: left)
drawer.mainScale = 0.8
drawer.containerView.backgroundColor = #colorLiteral(red: 0.2392156869, green: 0.6745098233, blue: 0.9686274529, alpha: 1)
drawer.drawerStyle = .plain
Expand Down
18 changes: 6 additions & 12 deletions ZKDrawerController/Core/ZKDrawerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,13 @@ open class ZKDrawerController: UIViewController, ZKDrawerCoverViewDelegate {
fatalError("init(coder:) has not been implemented")
}

/// 解决左侧抽屉划出手势和导航控制器手势冲突的问题, 默认在ZKDrawerController初始化时会进行调用
///
/// - Parameter vc: 导航控制器 或者包含了导航控制器的父控制器
open func resolveGestureConflict(vc: UIViewController) {
if let nav = vc as? UINavigationController {
if let gesture = nav.interactivePopGestureRecognizer {
containerView.panGestureRecognizer.require(toFail: gesture)
}
/// default true, 解决左侧抽屉划出手势和导航控制器手势冲突的问题
open var shouldRequireFailureOfNavigationPopGesture: Bool {
get {
return containerView.shouldRequireFailureOfNavigationPopGesture
}
for childVC in vc.childViewControllers {
resolveGestureConflict(vc: childVC)
set {
containerView.shouldRequireFailureOfNavigationPopGesture = newValue
}
}

Expand Down Expand Up @@ -251,8 +247,6 @@ open class ZKDrawerController: UIViewController, ZKDrawerCoverViewDelegate {
make.right.equalTo(-rightWidth)
make.width.equalToSuperview()
}
// 如果主视图控制器包含导航控制器, 导航手势失败才可以执行左侧菜单手势
resolveGestureConflict(vc: vc)
}

func removeOldVC(vc: UIViewController?) {
Expand Down
15 changes: 14 additions & 1 deletion ZKDrawerController/Core/ZKDrawerScrollView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import UIKit
import SnapKit

public class ZKDrawerScrollView: UIScrollView {
public class ZKDrawerScrollView: UIScrollView, UIGestureRecognizerDelegate {

var rightWidth: CGFloat = 0

Expand All @@ -21,13 +21,16 @@ public class ZKDrawerScrollView: UIScrollView {

var gestureRecognizerWidth:CGFloat = 40

var shouldRequireFailureOfNavigationPopGesture: Bool = true

public override init(frame: CGRect) {
super.init(frame: frame)

self.backgroundColor = UIColor.clear
self.showsHorizontalScrollIndicator = false
self.bounces = false
self.isPagingEnabled = true
self.panGestureRecognizer.delegate = self
}

public required init?(coder aDecoder: NSCoder) {
Expand Down Expand Up @@ -65,6 +68,16 @@ public class ZKDrawerScrollView: UIScrollView {
}
return false
}

public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRequireFailureOf otherGestureRecognizer: UIGestureRecognizer) -> Bool {
if otherGestureRecognizer is UIScreenEdgePanGestureRecognizer {
return shouldRequireFailureOfNavigationPopGesture
} else {
return false
}
}


// public override func setContentOffset(_ contentOffset: CGPoint, animated: Bool) {
// super.setContentOffset(contentOffset, animated: animated)
// if animated && contentOffset != self.contentOffset {
Expand Down
2 changes: 1 addition & 1 deletion ZKDrawerController/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ViewController: UIViewController {
view.backgroundColor = UIColor.blue

//navigationItem.rightBarButtonItem = UIBarButtonItem.init(title: "show", style: .plain, target: self, action: #selector(showRight))
navigationItem.leftBarButtonItem = UIBarButtonItem.init(title: "show", style: .plain, target: self, action: #selector(showLeft))
// navigationItem.leftBarButtonItem = UIBarButtonItem.init(title: "show", style: .plain, target: self, action: #selector(showLeft))
// Do any additional setup after loading the view, typically from a nib.

let button = UIButton.init(frame: CGRect.init(x: 200, y: 200, width: 150, height: 100))
Expand Down

0 comments on commit a07a085

Please sign in to comment.