SWRevealViewController close rear view when tapping front view

前端 未结 9 1623
夕颜
夕颜 2020-12-09 04:18

I am using SWRevealViewController in order to implement a side nav menu in my app. I would like to make it so that the front view cannot be interacted with when

9条回答
  •  孤街浪徒
    2020-12-09 04:51

    I used the tapGestureRecognizer but there are still some problems. I tried this and worked great!

    Define class:

    @interface IgnoreView : UIView
    
    @property (nonatomic, assign) BOOL shouldAllTouchesBeForMe;
    
    @end
    

    Implement:

    @implementation IgnoreView
    
    - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
    {
        if( self.shouldAllTouchesBeForMe ){
            return self;
        }
        return [super hitTest:point withEvent:event];
    }
    
    @end
    

    Then make your View class in Interface Builder of class IgnoreView

    In your ViewController, then, do:

    in - viewDidLoad

    self.revealViewController.delegate = self;
    [self.view addGestureRecognizer:self.revealViewController.tapGestureRecognizer];
    

    the implement in your viewcontroller also:

    - (void)revealController:(SWRevealViewController *)revealController didMoveToPosition:(FrontViewPosition)position
    {
        IgnoreView *i = (id)self.view;
        i.shouldAllTouchesBeForMe = position == FrontViewPositionRight;
    }
    

    And you're all set!

提交回复
热议问题