[英]Detect long tap in UIScrollView
如何在UIScrollView中检测到长按(点击并按住)?
In view's touchesBegan:
you can call your "long tap" handle with some delay. 在视图中触摸开始touchesBegan:
你可以稍微调用你的“长按”手柄。
[touchHandler performSelector:@selector(longTap:) withObject:nil afterDelay:1.5];
Then in view's touchesEnded:
you can cancel that call if not enough time has passed: 然后在视图的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");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.