我使用SWReveal视图控制器创建了侧面菜单结构。我想要做的是取消在某些页面上打开右侧视图控制器。我已经研究并发现了类似这样的内容:
- (BOOL)revealControllerPanGestureShouldBegin:(SWRevealViewController *)revealController
if([revealController.frontViewController isKindOfClass:[UINavigationController class]]){
UINavigationController *navController = (UINavigationController *)revealController.frontViewController;
UIViewController *lastViewController = navController.viewControllers.lastObject;
if([lastViewController isKindOfClass:[DetailViewController class]] ||
[lastViewController isKindOfClass:[TableDateViewController class]] ||
[lastViewController isKindOfClass:[MapViewController class]])
{
return NO; // I do not want to open it for the view controllers I want
}
}
return YES;
}
这对我有用,但它也影响了左页的打开。触摸动作(点击手势)没有问题,但这适用于平移手势。我的意思是平移手势不适用于视图控制器我想运行。我想为某些视图控制器正常工作,但我不想影响左侧。 我添加了这样的权利切换:
-(void)sideRightMenuLoad{
[((PersonelViewController *)[self.navigationController.viewControllers objectAtIndex:0]).view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
SWRevealViewController *revealViewController = self.revealViewController;
if(revealViewController){
[self.sideRightBarButton setTarget:self.revealViewController];
[self.sideRightBarButton setAction:@selector(rightRevealToggle:)];
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
}
此代码需要打开右侧页面:
[self performSegueWithIdentifier:SWSegueRightIdentifier sender:nil];
我试图在我想要的时候运行它,但它没有用。 我正在等待这方面的帮助。谢谢。
答案 0 :(得分:1)
你必须检查平移手势的方向:
- (BOOL)revealControllerPanGestureShouldBegin:(SWRevealViewController *)revealController {
if ([revealController.panGestureRecognizer velocityInView:revealController.view].x < 0) {
// pan direction left, should open right side
// ...
return NO;
}
return YES;
}
答案 1 :(得分:1)
SWIFT 4
func revealControllerPanGestureShouldBegin(_ revealController: SWRevealViewController!) -> Bool {
let point = revealController.panGestureRecognizer().location(in: self.view)
if revealController.frontViewPosition == FrontViewPosition.left && point.x < 50.0 {
print("YES YES YES YES RRRRIIIIGGGGHHHHTTTT")
return false
}
else if revealController.frontViewPosition == FrontViewPosition.right {
print("YES YES YES YES LLLLEEEEFFFFTTTT")
return true
}
return false
}