SWRevealViewController: Remove interaction on frontview when rearview is revealed

前端 未结 15 1302
迷失自我
迷失自我 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:35

    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.

提交回复
热议问题