我在UIPanGestureRecognizer
:
UIScrollView
存在以下问题
UIScrollView *sv = [[UIScrollView alloc] initWithFrame:CGRectMake(200, 200, 200, 200)];
sv.contentSize = CGSizeMake(200, 100 *100);
for (int i = 0; i < 100; i++) {
UIView *newView = [[UIView alloc] initWithFrame:CGRectMake(0, i * 100, 200, 100)];
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panTile:)];
[panGesture setDelegate:self];
[panGesture setEnabled:FALSE];
[newView addGestureRecognizer:panGesture];
UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
[longPressRecognizer setDelegate:self];
[newView addGestureRecognizer:longPressRecognizer];
[sv addSubview:newView];
}
完整的滚动视图中填充了小块,每个块都实现了一个平移手势,以使它们可以拖动。问题是 - 这样做 - 阻止滚动视图滚动。拖动瓷砖反而很好。当我禁用平铺手势时,滚动效果很好。瓷砖平移手势有点隐藏滚动视图自己的平移手势。我的想法是从一开始就禁用瓷砖平移手势。一旦用户长时间按下图块,就启用手势。问题是用户必须抬起手指然后再次触摸瓷砖以拖动它。拖动完成后,我启用长按并再次禁用平移手势。所以longPress:
如下所示:
- (void)longPress:(UILongPressGestureRecognizer *) gestureRecognizer {
for (UIGestureRecognizer *r in gestureRecognizer.view.gestureRecognizers) {
if ([r isKindOfClass:[UIPanGestureRecognizer class]]) {
[r setEnabled:TRUE];
}
}
//pan gesture should take over here...
}
是否有可能将长按和平移手势粘在一起,以便用户不必抬起手指?或者可能是另一种解决方案?