我在我的应用程序中使用John Lluch的SWRevealViewController,当侧边栏出来并且用户想要关闭它时,不断点击前视图。
我想要做的是在显示侧边栏(后视图)时禁用前视图,但这并不像我想象的那么容易。禁用前视图(self.revealViewController.frontViewController.view.userInteractionEnabled = NO;
)时,手势监听器和显示按钮侦听器也会被禁用,因此用户无法再次关闭侧栏。
所以有人解决了类似的问题吗?如何禁用视图控制器的特定组件?我试着查看对象并找到正确的子视图,但它太复杂而且很难看。
感谢您的任何意见!
答案 0 :(得分:2)
在您的viewcontroller中添加SWRevealViewControllerDelegate
SWRevealViewController *revealViewController;
在视图DidLoad中调用以下方法
- (void)customSetup
{
revealViewController = self.revealViewController;
revealViewController.delegate=self;
if ( revealViewController )
{
// revealViewController.toggleAnimationDuration = 0.75;
[revealViewController panGestureRecognizer];
[revealViewController tapGestureRecognizer];
// revealViewController.panGestureRecognizer.enabled = NO;
}
}
在您的设置按钮/侧栏按钮
上添加以下方法- (IBAction)butBack_actionforMain:(id)sender {
[self hideWaitingHud];
self.navigationController.interactivePopGestureRecognizer.delegate = self;
self.navigationItem.leftBarButtonItem.target = self.revealViewController;
self.navigationItem.leftBarButtonItem.action = @selector(revealToggle:);
[self.revealViewController revealToggle:sender];
// Set the gesture
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
}
如果你想在委托方法中做点什么
- (void)revealController:(SWRevealViewController *)revealController didMoveToPosition:(FrontViewPosition)position
{
UIWindow *mainWindow = [[UIApplication sharedApplication] keyWindow];
CGPoint windowPoint = [self.view convertPoint:self.view.bounds.origin toView:mainWindow];
NSLog(@"the window position ==%.2f",windowPoint.x);
if (windowPoint.x>0.0)
{
// set to NO
//self.btnHKV.userInteractionEnabled=YES;
revealViewController.panGestureRecognizer.enabled = NO;
self.view.userInteractionEnabled = NO;
}
else
{
// set to YES
//self.btnHKV.userInteractionEnabled=YES;
self.view.userInteractionEnabled = YES;
revealViewController.panGestureRecognizer.enabled = YES;
}
}