问题描述
我需要在显示后视图时禁用前视图上的用户交互。发现其他人问同样的事情但却无法真正理解我在哪里或如何实现我见过的代码。
例如:我从链接,
- (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;
}
}
还找到其他一些链接
我有这段代码,但不确定插入此代码的正确位置。我已经尝试在我的前/后视图中添加它,也在 SWRevealViewController
方法中添加它没有成功
欣赏如果有人可以指出我正确的方向。
我最近提出了一个我想分享的解决方案
(对不起,如果迟到2个月)。
要在菜单打开时禁用前视图上的用户交互,我在 MenuViewController :
viewWillAppear :
[self.revealViewController.frontViewController.view setUserInteractionEnabled:NO];
和 viewWillDisappear :
[self.revealViewController.frontViewController.view setUserInteractionEnabled:YES];
这将禁用前视图控制器上的所有用户交互,这意味着滑动/点击手势为CLOSE菜单也将被禁用。
现在,我创建了一个 ParentViewController ,并使所有视图控制器(菜单项)成为子类我的 viewDidLoad 上的
,我输入以下代码:
SWRevealViewController * revealController = [self revealViewController];
[revealController panGestureRecognizer];
[revealController tapGestureRecognizer];
如果您此时运行应用程序,则可能会出现Tap Gesture工作(点按前视图将关闭菜单,但不是平移手势。我不确定为什么会这样,但为了使滑动手势能够关闭您的菜单,请在 MenuViewController 中添加以下代码:
on viewWillAppear :
[self.revealViewController.view addGestureRecognizer:self.revealViewController.panGestureRecognizer ]。
总结一下,这就是你需要的:
在 MenuViewController 上:
- (void)viewWillAppear: (BOOL)动画{
[super viewWillAppear:animated];
[self.revealViewController.frontViewController.view setUserInteractionEnabled:NO];
[self.revealViewController.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
}
- (void)viewDidDisappear:(BOOL)动画{
[super viewDidDisappear:animated];
[self.revealViewController.frontViewController.view setUserInteractionEnabled:YES];
}
在菜单项的视图控制器上(你可以做一个所有人都使用ParentViewController :
- (void)viewDidLoad {
[super viewDidLoad];
SWRevealViewController * revealController = [self revealViewController];
[revealController panGestureRecognizer];
[revealController tapGestureRecognizer];
}
希望这会有所帮助!
I need to disable user interaction on front view when rear view is revealed. Found some others asking the same thing but can't really understand where or how to implement the code that I've seen.
Ex: I found this code from link,
- (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;
}
}
Also found few other links
I have this code, but not really sure about the correct place to insert this code. I've tried adding it in my front/rear views and also in the SWRevealViewController
method with no success
Appreciate if someone can point me in the right direction.
I've recently come up with a solution that I wanted to share(sorry if it's 2 months late).
To disable user interaction on the Front View while the Menu is open, I added the following codes on my MenuViewController:
on viewWillAppear:
[self.revealViewController.frontViewController.view setUserInteractionEnabled:NO];
and on viewWillDisappear:
[self.revealViewController.frontViewController.view setUserInteractionEnabled:YES];
This will disable all user interactions on the Front View Controller, which means that the slide / tap gestures to CLOSE the menu will also be DISABLED.
Now, I have created a ParentViewController and made all the view controllers (the menu items) a subclass of it.
on my viewDidLoad, I put the following codes:
SWRevealViewController *revealController = [self revealViewController];
[revealController panGestureRecognizer];
[revealController tapGestureRecognizer];
If you run your app at this point, it would appear that the Tap Gesture works (a tap on the Front View will close the Menu), but NOT the Pan Gesture. I'm not sure why this is so, but in order to enable the slide gesture to CLOSE your menu, add the following code in your MenuViewController:
on viewWillAppear:
[self.revealViewController.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
To summarize, here's what you need:
On your MenuViewController:
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.revealViewController.frontViewController.view setUserInteractionEnabled:NO];
[self.revealViewController.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
}
-(void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[self.revealViewController.frontViewController.view setUserInteractionEnabled:YES];
}
And on your menu items' view controller (you can make a ParentViewController for all of them):
-(void)viewDidLoad {
[super viewDidLoad];
SWRevealViewController *revealController = [self revealViewController];
[revealController panGestureRecognizer];
[revealController tapGestureRecognizer];
}
Hope this helps!
这篇关于SWRevealViewController:在显示后视图时删除前视图上的交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!