2013-05-28 20 views
2

如何检测UITableView上的垂直UIPanGestureRecognizer。我可以检测水平,但仅在垂直方向上显示UITableView卷轴,而且我无法获取平移事件。在UITableView中检测垂直扫视

回答

6

UITableViewUIScrollview子类,所以你可以弄个很panGestureRecognizer,并添加自己的行动目标。

+1

你能详细说明吗? – scord

2

的UITableView的是的UIScrollView的子类,那么你就可以访问panGestureRecognizer财产

panGestureRecognizer的基本手势识别泛 手势。 (只读)

@属性(非原子,只读)UIPanGestureRecognizer * panGestureRecognizer

也见的UITableViewDelegate方法

4

有关使用UITableView小号的委托,而不是什么? UITableViewDelegate符合UIScrollViewDelegate,所以你可以使用任何的这些方法,例如:

– scrollViewDidScroll: 
– scrollViewWillBeginDragging: 
– scrollViewWillEndDragging:withVelocity:targetContentOffset: 
– scrollViewDidEndDragging:willDecelerate: 
+0

我有一个标签栏说,一半的屏幕和键盘打开我想撤销键盘一旦平移到达标签栏框架。如何从平移中检测与UIScreen相关的触摸点,以便我关闭键盘? – Hassy

+0

滚动代表的结果似乎并不是我所需要的 – Hassy

+1

如果你确实需要泛识别器,那么Mike Pollard的答案似乎很好。也许通过期望的行为或者你想用识别器实现的内容来扩展你的问题。它可以给你更好的答案:-) –

0

希望这对你有所帮助。

typedef enum : NSInteger 
{ 
    kPanMoveDirectionNone, 
    kPanMoveDirectionUp, 
    kPanMoveDirectionDown, 
    kPanMoveDirectionRight, 
    kPanMoveDirectionLeft 
} PanMoveDirection; 

-(PanMoveDirection)determineDirectionIfNeeded:(CGPoint)translation 
{ 
if (direction != kPanMoveDirectionNone) 
    return direction; 

// determine if horizontal swipe only if you meet some minimum velocity 

if (fabs(translation.x) > 20) 
{ 
    BOOL gestureHorizontal = NO; 

    if (translation.y == 0.0) 
     gestureHorizontal = YES; 
    else 
     gestureHorizontal = (fabs(translation.x/translation.y) > 5.0); 

    if (gestureHorizontal) 
    { 
     if (translation.x > 0.0) 
      return kPanMoveDirectionRight; 
     else 
      return kPanMoveDirectionLeft; 
    } 
} 
// determine if vertical swipe only if you meet some minimum velocity 

else if (fabs(translation.y) > 20) 
{ 
    BOOL gestureVertical = NO; 

    if (translation.x == 0.0) 
     gestureVertical = YES; 
    else 
     gestureVertical = (fabs(translation.y/translation.x) > 5.0); 

    if (gestureVertical) 
    { 
     if (translation.y > 0.0) 
      return kPanMoveDirectionDown; 
     else 
      return kPanMoveDirectionUp; 
    } 
} 
return direction; 
} 

call direction = [self determineDirectionIfNeeded:translation];在你的pangesture有针对性的方法