문제

How can I detect vertical UIPanGestureRecognizer on UITableView. I can detect horizontal but on vertical only the UITableView scrolls, and I can't get panning events.

도움이 되었습니까?

해결책

UITableView is a subclass of UIScrollview so you can get hold of it's panGestureRecognizer and add your own action targets.

다른 팁

What about using UITableViews delegate instead? UITableViewDelegate conforms to UIScrollViewDelegate so you can use any of these methods for example:

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

the UITableView is a subclass of UIScrollView, then you can access the panGestureRecognizer property

panGestureRecognizer The underlying gesture recognizer for pan gestures. (read-only)

@property(nonatomic, readonly) UIPanGestureRecognizer *panGestureRecognizer

See also the UItableViewDelegate methods

Hope this help you.

 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]; in your pangesture targeted method

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top