gpt4 book ai didi

swift - 实现 UINavigationControllerDelegates animationControllerFor 方法禁用边缘滑动弹出功能

转载 作者:行者123 更新时间:2023-11-28 08:25:08 25 4
gpt4 key购买 nike

短:实现 func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? from UINavigationControllerDelegate

导致边缘滑动弹出功能不起作用

有点长:我正在实现上面提到的委托(delegate)方法来确定呈现 View Controller 的状态,这部分效果很好。我在方法内部返回 nil,因为我实际上不需要任何 animationController 来实现花哨的效果。但是实现此方法会导致边缘滑动弹出功能/手势不起作用。我尝试通过各种方法获取默认行为,例如实现动画 Controller 或交互 Controller ,甚至尝试获取默认动画/交互 Controller ,但这也不起作用。我可以将手势识别器应用于整个 View ,但这不是预期的行为。

有没有人遇到过类似的问题,是否有我不知道的解决方案?

以 NavigationController 为例:

class MyNavigationController: UINavigationController {
override init(navigationBarClass: AnyClass?, toolbarClass: AnyClass?) {
super.init(navigationBarClass: navigationBarClass, toolbarClass: toolbarClass)

delegate = self
}

override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

extension MyNavigationController: UINavigationControllerDelegate {
func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
//removing or commenting out this method enables the edge-swipe-back feature/gesture
return nil
}
}

最佳答案

在您的init 方法中,您需要设置:


self.interactivePopGestureRecognizer.delegate = self

这将重新启用此功能。

关于swift - 实现 UINavigationControllerDelegates animationControllerFor 方法禁用边缘滑动弹出功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40239705/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com