侧滑手势:Modal侧边滑动Dismiss

- (instancetype)init
{
    self = [super init];
    if (self) {
        // 1. 在父类统一集成,子类通过_swipeDismissEnable属性开启
        self.swipeDismissEnable = NO;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 2. 创建侧滑手势
    if (self.swipeDismissEnable)
    {
        UIScreenEdgePanGestureRecognizer *edgePan;
        edgePan = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(interactiveTransitionRecognizerAction:)];
        // 可以拓展为其它侧边滑动手势(如:右侧边滑动进行present...)
        edgePan.edges = UIRectEdgeLeft; 
        [self.view addGestureRecognizer:edgePan];
    }
*/

}

// MARK: - 侧滑Dismiss
- (void)interactiveTransitionRecognizerAction:(UIScreenEdgePanGestureRecognizer *)sender
{
    if (self.swipeDismissEnable && sender.state == UIGestureRecognizerStateBegan)
    {
        // 可以此处可以做出判断是需要执行Dismiss操作还是Pop操作
        // 此处以Dismiss为列
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}

你可能感兴趣的:(侧滑手势:Modal侧边滑动Dismiss)