美文网首页
侧滑手势:Modal侧边滑动Dismiss

侧滑手势:Modal侧边滑动Dismiss

作者: Gxdy | 来源:发表于2017-12-15 11:12 被阅读0次
    - (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

          本文链接:https://www.haomeiwen.com/subject/lmbrwxtx.html