0

我在我的应用程序中使用了 John Lluch 的 SWRevealViewController,当侧边栏出现并且用户想要关闭它时,会不断单击前视图。

我想要做的是在显示侧边栏(后视图)时禁用前视图,但这并不像我想象的那么容易。禁用前视图 ( self.revealViewController.frontViewController.view.userInteractionEnabled = NO;) 时,手势监听器和显示按钮监听器也被禁用,因此用户无法再次关闭侧边栏。

那么有没有人解决过类似的问题?如何禁用视图控制器的特定组件?我尝试查看对象并找到正确的子视图,但它太复杂而且很难看。

感谢您对此的任何意见!

4

1 回答 1

2

添加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;



 }


}
于 2015-10-01T09:47:10.870 回答