在UITableView中检测垂直平移

时间:2013-05-28 09:50:50

标签: ios objective-c uipangesturerecognizer

如何在UIPanGestureRecognizer上检测垂直UITableView。我可以检测水平但仅在垂直方向上检测UITableView卷轴,我无法获得平移事件。

4 个答案:

答案 0 :(得分:6)

UITableViewUIScrollview的子类,因此您可以抓住它panGestureRecognizer并添加自己的行动目标。

答案 1 :(得分:4)

如何使用UITableView代理呢? UITableViewDelegate符合UIScrollViewDelegate,因此您可以使用以下任何一种方法:

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

答案 2 :(得分:2)

UITableView是UIScrollView的子类,然后你可以访问panGestureRecognizer属性

  

panGestureRecognizer pan的基础手势识别器   手势。 (只读)

     

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

另请参阅UItableViewDelegate方法

答案 3 :(得分: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目标方法