【问题标题】:UIScrollView velocity 0 while decelerating减速时 UIScrollView 速度为 0
【发布时间】:2016-05-18 19:42:26
【问题描述】:

我需要检测用户滚动方向以防止错误滑动。我使用以下代码

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

        CGPoint velocity = [(UIPanGestureRecognizer *)gestureRecognizer velocityInView:self];


            if (fabs(velocity.y) * 2 < fabs(velocity.x))
            {
                //scroll LEFT or RIGHT 
                return NO;
            }
            else
            {
                //scroll UP or DOWN 
            }


         return YES;
}

它在大多数情况下都有效,除非用户在滚动视图减速时滚动,那么速度因子为空,我无法计算滚动方向。

编辑 1

类似问题:link

【问题讨论】:

  • 将 contentsize 设置为屏幕宽度,它不会从左到右滚动
  • 我在水平 pageViewController 中使用垂直 collectionView。当用户向上/向下滚动 collectionView 时,我需要防止模糊的左/右滑动。除非 collectionView 正在减速,否则它可以工作。

标签: ios objective-c uiscrollview


【解决方案1】:

我认为最简单的解决方案是直接在UIScrollViewDelegate 上检测滚动方向。看看this answer

【讨论】:

  • 我需要知道 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer 方法中的方向来阻止任何错误的手势
猜你喜欢
  • 2013-08-26
  • 2013-04-29
  • 2010-11-09
  • 2011-08-27
  • 2011-01-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多