美文网首页
iOS手势上下拖拽优化问题

iOS手势上下拖拽优化问题

作者: 新地球说着一口陌生腔调 | 来源:发表于2019-11-01 11:26 被阅读0次

有时候有个需求是需要页面上下拖拽来实现某些交互,我们一下想到的使用UISwipeGestureRecognizer类,但是这个缺点是稍微一滑动就能触发,这个往往是用户不能接受的,那我们如何优化?


使用UIPanGestureRecognizer类来优化这个拖拽敏感度问题!计算当前滑动的幅度大小

代码如下:


        UIPanGestureRecognizer*panGestureRecognizer = [[UIPanGestureRecognizeralloc]initWithTarget:selfaction:@selector(panGestureAction:)];

        panGestureRecognizer.delegate=self;

        [_tableView addGestureRecognizer:panGestureRecognizer];

- (void)panGestureAction:(UIPanGestureRecognizer *)recognizer{

    CGPoint translation = [recognizer translationInView:recognizer.view];

    NSLog(@"translation:%@",NSStringFromCGPoint(translation));

    if(translation.y<-80){//上拖拽

        //直接设置到顶部

        [_headerView mas_updateConstraints:^(MASConstraintMaker *make) {

            make.top.offset(-300);

        }];   

}elseif(translation.y>80){

        [_headerView mas_updateConstraints:^(MASConstraintMaker *make) {

            make.top.offset(0);

        }];

    }

}

相关文章

网友评论

      本文标题:iOS手势上下拖拽优化问题

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