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