是否可以增加 UINavigationController 的边缘大小 interactivePopGestureRecognizer
来响应用户触摸?
即是否可以从屏幕中间向右滑动来移动并弹出当前顶部 View Controller ,方式与从屏幕左边缘相同?
最佳答案
override func viewDidLoad() {
super.viewDidLoad()
let swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(respondToSwipeGesture))
swipeRight.direction = .right
self.view.addGestureRecognizer(swipeRight)
let swipeLeft = UISwipeGestureRecognizer(target: self, action: #selector(respondToSwipeGesture))
swipeLeft.direction = .left
self.view.addGestureRecognizer(swipeLeft)
}
// you can track all direction swipe like below, and to do that first you have to add gesture in the view you want to track.
@objc func respondToSwipeGesture(gesture: UIGestureRecognizer) {
if let swipeGesture = gesture as? UISwipeGestureRecognizer {
switch swipeGesture.direction {
case .right:
// push pop here
print("Swiped right")
case .down:
print("Swiped down")
case .left:
// push pop here
print("Swiped left")
case .up:
print("Swiped up")
default:
break
}
}
}
关于ios - 向右滑动可关闭边缘尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59482739/