我有一个UIViewController,它被推到导航堆栈上。我想扩展标准的iOS7交互式pan手势,将该视图控制器弹出到默认的UIRectEdgeLeft边界之外,这样用户就可以通过从视图上的任何位置进行摇摄来启动交互式回退操作。
我尝试过自己的交互式视图控制器转换,但要完全复制默认interactivePopGestureRecognizer的良好视差处理非常麻烦。例如,fromViewController隐藏导航条,而toViewController则显示它--这在自定义交互转换中不容易处理,但在默认操作中是无缝的。
因此,我想将默认操作扩展到更大范围的pan手势,但是API似乎不支持简单地替换手势。
有什么创造性的建议吗?
发布于 2014-06-01 13:07:05
查看我的库SloppySwiper,它通过使用UIPanGestureRecognizer和重新创建默认动画来实现这一点。您还可以在https://github.com/fastred/SloppySwiper/issues/1中看到我的想法。
发布于 2020-03-04 12:40:29
实际上,在UINavigationController子类上进行操作非常容易,而不需要对每个UIViewController子类进行任何干预。还尊重内置的从边缘滑动的状态(因此,当由于某种原因而禁用时,新的姿态也被禁用):
import UIKit
class NavigationController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
setupFullWidthBackGesture()
}
private lazy var fullWidthBackGestureRecognizer = UIPanGestureRecognizer()
private func setupFullWidthBackGesture() {
// The trick here is to wire up our full-width `fullWidthBackGestureRecognizer` to execute the same handler as
// the system `interactivePopGestureRecognizer`. That's done by assigning the same "targets" (effectively
// object and selector) of the system one to our gesture recognizer.
guard
let interactivePopGestureRecognizer = interactivePopGestureRecognizer,
let targets = interactivePopGestureRecognizer.value(forKey: "targets")
else {
return
}
fullWidthBackGestureRecognizer.setValue(targets, forKey: "targets")
fullWidthBackGestureRecognizer.delegate = self
view.addGestureRecognizer(fullWidthBackGestureRecognizer)
}
}
extension NavigationController: UIGestureRecognizerDelegate {
func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
let isSystemSwipeToBackEnabled = interactivePopGestureRecognizer?.isEnabled == true
let isThereStackedViewControllers = viewControllers.count > 1
return isSystemSwipeToBackEnabled && isThereStackedViewControllers
}
}https://stackoverflow.com/questions/20714595
复制相似问题