2

如何UIPanGestureRecognizerUITableView. 我只能检测水平但垂直的UITableView滚动,我无法获得平移事件。

4

4 回答 4

6

UITableView是的子类,UIScrollview因此您可以掌握它panGestureRecognizer并添加自己的操作目标。

于 2013-05-28T09:59:19.080 回答
4

那么使用UITableViews 委托呢?UITableViewDelegate符合,UIScrollViewDelegate因此您可以使用这些方法中的任何一种,例如:

– scrollViewDidScroll:
– scrollViewWillBeginDragging:
– scrollViewWillEndDragging:withVelocity:targetContentOffset:
– scrollViewDidEndDragging:willDecelerate:
于 2013-05-28T09:56:24.553 回答
2

UITableView 是 UIScrollView 的子类,那么你可以访问 panGestureRecognizer 属性

panGestureRecognizer 用于平移手势的底层手势识别器。(只读)

@property(nonatomic, readonly) UIPanGestureRecognizer *panGestureRecognizer

另请参阅 UItableViewDelegate 方法

于 2013-05-28T09:55:58.553 回答
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;
}

呼叫方向 = [self determineDirectionIfNeeded:translation]; 在您的定位方法中

于 2013-05-29T01:07:03.113 回答