代码之家  ›  专栏  ›  技术社区  ›  Luca Sarif

如何禁用仅在一个视图控制器上的回扫

  •  0
  • Luca Sarif  · 技术社区  · 8 年前

    我知道有人问过类似的问题,但没有一个对我有用。

    我有这个代码可以在我的项目中向后滑动

        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
        }
    }
    

    我有这个风险投资组合

    homescreenvc->登录/signupvc->用户配置文件vc

    我不希望他们能够从userprofilevc刷回来。

    2 回复  |  直到 8 年前
        1
  •  1
  •   Shehata Gamal    8 年前

    一个更好的方法是在显示时从堆栈中清除它们 UserProfileVC

    let profile  = self.storyboard?.instantiateViewController(withIdentifier: "profileID") as! UserProfileVC
    self.navigationController?.viewControllers = [profile]
    

    编辑: 在profilevc中执行此操作

    self.navigationController?.viewControllers = [self]
    

    / /

    self.view.alpha = 0
    
    UIView.animate(withDuration: 0.5) {
    
        self.view.alpha = 1
    
    }
    
        2
  •  0
  •   Ashutos Sahoo    8 年前

    我认为你也可以从那里删除手势识别器,为什么你不尝试。 尝试这样的方法:

    视图.格式识别器?删除()

    推荐文章