我知道有人问过类似的问题,但没有一个对我有用。
我有这段代码可以在项目中向后滑动
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->登录/注册VC-> UserProfileVC
我不希望他们能够从UserProfileVC向后滑动。
答案 0 :(得分:1)
一种更好的方法是在显示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
}
答案 1 :(得分:0)
我认为您也可以从那里删除手势识别器,原因就是您不尝试这样做。 尝试这样的事情:-
view.gestureRecognizers?.removeAll()