SWRevealViewController: Remove interaction on frontview when rearview is revealed

前端 未结 15 1242
迷失自我
迷失自我 2020-12-24 10:05

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 t

15条回答
  •  天涯浪人
    2020-12-24 10:47

    As John Explained: Although these solutions do work, I don't think any of them address the original question, which is actually quite simple:

    There are 2 steps involved:

    1. Add the following methods to your FrontViewController.m:

      • (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; } }

    2. Make your front view controller be a delegate of SWRevealViewController in the FrontViewController.h file:

    (e.g. @interface HomeViewController : UIViewController ) where my FrontViewController was named HomeViewController

    and also in the FrontViewController.m file with the following on ViewDidLoad:

    self.revealViewController.delegate = self; Problem solved! Much easier than creating parent classes, etc.

    This will help you solve the user interactions for the FrontView controller lovely I would just add the following change taken from Xun's response also above and you will solve both the user interactions and the hide menu when user taps FrontViewController.

    - (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;
          //Hides the menu when user taps FrontViewController
           [revealController.frontViewController.revealViewController tapGestureRecognizer];
        } 
    }
    

提交回复
热议问题