如何在UIPanGestureRecognizer
上检测垂直UITableView
。我可以检测水平但仅在垂直方向上检测UITableView
卷轴,我无法获得平移事件。
答案 0 :(得分:6)
UITableView
是UIScrollview
的子类,因此您可以抓住它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目标方法