美文网首页
侧滑手势

侧滑手势

作者: nothing_c | 来源:发表于2016-10-30 01:18 被阅读19次

    //创建侧滑手势并绑定方法

    UIScreenEdgePanGestureRecognize r*SEPGesture = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(gesture:)];

    //指定在哪个边缘侧滑UIRectEdgeNone UIRectEdgeTop UIRectEdgeLeft UIRectEdgeBottom UIRectEdgeRight UIRectEdgeAll

    SEPGesture.edges=UIRectEdgeLeft;

    //设置代理导人UIGestureRecognizerDelegate可实现下面两个BOOL的方法

    SEPGesture.delegate=self;

    //添加

    [self.viewaddGestureRecognizer:SEPGesture];

    }

    //返回手势是否执行

    - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {

    //由于这个类是要ios7以上的版本才可使用进行判断可避免运行崩溃

    if([[UIDevicecurrentDevice].systemVersionfloatValue] >= 7.0) {

    //判断是不是侧滑的类

    if([gestureRecognizer isKindOfClass:[UIScreenEdgePanGestureRecognizer class]]) {

    return YES;

    }

    }

    return NO;

    }

    //失败时返回,other是否有效,如果gestureRecognizer失效时,就使用otherGestureRecognizer

    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {

    if([gestureRecognizer isKindOfClass:[UIScreenEdgePanGestureRecognizer class]]) {

    return YES;

    }

    return NO;

    }

    - (void)gesture:(UIScreenEdgePanGestureRecognizer *)gesture {

    [self.navigationController popToRootViewControllerAnimated:YES];

    }

    相关文章

      网友评论

          本文标题:侧滑手势

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