【发布时间】:2010-04-06 14:21:16
【问题描述】:
如何检测 UIScrollView 中的长按(长按)?
【问题讨论】:
标签: iphone cocoa-touch iphone-sdk-3.0
如何检测 UIScrollView 中的长按(长按)?
【问题讨论】:
标签: iphone cocoa-touch iphone-sdk-3.0
在视图的touchesBegan: 中,您可以稍稍延迟调用您的“长按”句柄。
[touchHandler performSelector:@selector(longTap:) withObject:nil afterDelay:1.5];
然后在视图的touchesEnded: 中,如果没有足够的时间,您可以取消该调用:
[NSObject cancelPreviousPerformRequestsWithTarget:touchHandler selector:@selector(longTap:) object:nil];
【讨论】:
//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");
}
}
【讨论】: