Reputation: 5208
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.
Upvotes: 2
Views: 1168
Reputation: 63
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
Upvotes: 0
Reputation: 10195
UITableView
is a subclass of UIScrollview
so you can get hold of it's panGestureRecognizer
and add your own action targets.
Upvotes: 6
Reputation: 7704
What about using UITableView
s delegate instead? UITableViewDelegate
conforms to UIScrollViewDelegate
so you can use any of these methods for example:
– scrollViewDidScroll:
– scrollViewWillBeginDragging:
– scrollViewWillEndDragging:withVelocity:targetContentOffset:
– scrollViewDidEndDragging:willDecelerate:
Upvotes: 4
Reputation: 4551
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
Upvotes: 2