我正在使用SWRevealViewController来实现我的应用程序中的侧导航菜单.我想使它使得当后视图打开时,前视图不能与之互动,除非用户点击前视图,后视图将关闭,并且前视图可以再次进行交互.我有这两个SWRevealViewController委托方法,目前从前视图中删除交互.
- (void)revealController:(SWRevealViewController *)revealController willMoveToPosition: (FrontViewPosition)position { if(position == FrontViewPositionLeft) { self.view.userInteractionEnabled = YES; } else { self.view.userInteractionEnabled = NO; } } - (void)revealController:(SWRevealViewController *)revealController didMoveToPosition: (FrontViewPosition)position { if(position == FrontViewPositionLeft) { self.view.userInteractionEnabled = YES; } else { self.view.userInteractionEnabled = NO; } }
但是,当前视图被轻拍时,这并不会导致后视图关闭.任何帮助将不胜感激,谢谢!
解决方法
如果您使用SWIFT,您可以在frontViewController中执行此操作:
override func viewDidLoad() { super.viewDidLoad() if self.revealViewController() != nil { self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer()) self.view.addGestureRecognizer(self.revealViewController().tapGestureRecognizer()) } }
代码适用于TAP和PAN手势.