标签:
今天在做侧滑页面时,发现页面随着滑动手势而滑动,到临界点时,如果再滑动会出现抖动现象.找到解决办法是进入方法后先判断一次,再判断是在滑动范围内让页面滑动.遂将滑动手势(UIPanGestureRecognizer )注意事项总结了如下:
代码:
- (void)panAction:(UIPanGestureRecognizer *)pan{
_canLeft = YES;
_canRight = YES;
//点相对于上一个点的位置
CGPoint moviePoint = [pan translationInView:pan.view];
//点的速度(正负可判断滑动趋势)
CGPoint velocity = [pan velocityInView:pan.view];
//侧滑的范围
CGFloat instance = kScreenWidth - 100;
//禁止左划的情况(在最左边时)
if (pan.view.left <= 0 && moviePoint.x <= 0) {
_canLeft = NO;
}
//禁止右划得情况(在最右边时)
if (pan.view.left >= instance && moviePoint.x >= 0) {
_canRight = NO;
}
//页面可以滑动的条件
if (_canRight && _canLeft && pan.view.left >= 0 && pan.view.left <= instance){
//移动
pan.view.center =
CGPointMake(pan.view.center.x + moviePoint.x, pan.view.center.y);
}
//每次都需要复位
[pan setTranslation:CGPointZero inView:pan.view];
//松开手指时判断滑动趋势让其归位
if (pan.state == UIGestureRecognizerStateEnded) {
if (pan.view.left < 10) {
pan.view.left = 0;
}else if(pan.view.left > instance - 10){
pan.view.left = instance;
}
}
}
iOS滑动手势UIPanGestureRecognizer 注意事项
标签:
原文地址:http://www.cnblogs.com/duzhaoquan/p/5885679.html