在 UIScrollView 中检测长按
Posted
技术标签:
【中文标题】在 UIScrollView 中检测长按【英文标题】:Detect long tap in UIScrollView 【发布时间】:2010-04-06 14:21:16 【问题描述】:如何检测 UIScrollView 中的长按(长按)?
【问题讨论】:
【参考方案1】:在视图的touchesBegan:
中,您可以稍稍延迟调用您的“长按”句柄。
[touchHandler performSelector:@selector(longTap:) withObject:nil afterDelay:1.5];
然后在视图的touchesEnded:
中,如果没有足够的时间,您可以取消该调用:
[NSObject cancelPreviousPerformRequestsWithTarget:touchHandler selector:@selector(longTap:) object:nil];
【讨论】:
【参考方案2】://Add gesture to a method where the view is being created. In this example long tap is added to tile (a subclass of UIView):
// Add long tap for the main tiles
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longTap:)];
[tile addGestureRecognizer:longPressGesture];
[longPressGesture release];
-(void) longTap:(UILongPressGestureRecognizer *)gestureRecognizer
NSLog(@"gestureRecognizer= %@",gestureRecognizer);
if ([gestureRecognizer state] == UIGestureRecognizerStateBegan)
NSLog(@"longTap began");
【讨论】:
以上是关于在 UIScrollView 中检测长按的主要内容,如果未能解决你的问题,请参考以下文章