4
如何在UIScrollView中檢測長按(輕按並按住)?在UIScrollView中檢測長按
如何在UIScrollView中檢測長按(輕按並按住)?在UIScrollView中檢測長按
在視圖的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");
}
}
thanksssssssss!你救了我的命! (1) – SpaceDog 2010-04-17 15:11:07