iOS手势上下拖拽优化问题
有时候有个需求是需要页面上下拖拽来实现某些交互,我们一下想到的使用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);
}];
}
}