Swift 如何仅在一个视图控制器上禁用回扫
我知道有人问过类似的问题,但没有一个对我有用 我有这个代码,可以在我的项目中回刷Swift 如何仅在一个视图控制器上禁用回扫,swift,uigesturerecognizer,swipe,Swift,Uigesturerecognizer,Swipe,我知道有人问过类似的问题,但没有一个对我有用 我有这个代码,可以在我的项目中回刷 class InteractivePopRecognizer: NSObject { // MARK: - Properties fileprivate weak var navigationController: UINavigationController? // MARK: - Init init(controller: UINavigationControll
class InteractivePopRecognizer: NSObject {
// MARK: - Properties
fileprivate weak var navigationController: UINavigationController?
// MARK: - Init
init(controller: UINavigationController) {
self.navigationController = controller
super.init()
self.navigationController?.interactivePopGestureRecognizer?.delegate = self
}
}
extension InteractivePopRecognizer: UIGestureRecognizerDelegate {
func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
return (navigationController?.viewControllers.count ?? 0) > 1
}
// This is necessary because without it, subviews of your top controller can cancel out your gesture recognizer on the edge.
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}
}
我有这个VC堆栈
HomescreenVC->Login/SignupVC->UserProfileVC
我不希望它们能够从UserProfileVC刷回。更好的方法是在显示
UserProfileVC
let profile = self.storyboard?.instantiateViewController(withIdentifier: "profileID") as! UserProfileVC
self.navigationController?.viewControllers = [profile]
编辑:在profileVC中执行此操作
self.navigationController?.viewControllers = [self]
//
我认为你们也可以从那个里移除手势识别器,为什么你们不尝试那个呢。 试试这样的东西:-
view.gestureerecognizers?.removeAll()我尝试将其放入userprofilevc的viewDidLoad和ViewDidAspect中,但出现了一个错误,然后我尝试将其放在另一个VC的userprofilevc的segues之后,但也出现了一个错误。删除任何segue并在IB中为该配置文件提供一个标识符,然后像在回答中那样加载,这仍然不起作用。我需要看风景。是否有一种方法可以关闭当前视图控制器(UserProfileVC)下的所有视图控制器?是的,编辑不起作用-我还忘了提到UserProfileVC连接到选项卡栏控制器,对不起。谢谢你工作得很好。在我接受之前,是否有一种方法可以将UserProfileVC动画化,而不是仅仅显示出来。这不起作用,我仍然可以刷回。我想这是因为我在导航控制器上实例化了手势识别器,而不是实际的视图是的,这是由于这个原因,并通过放置导航来检查是否在视图位置。如果不工作,请检查此链接并尝试此链接
self.view.alpha = 0
UIView.animate(withDuration: 0.5) {
self.view.alpha = 1
}