iphone - LongPress手势在 iOS 5和 iOS 5.1上不工作( 但在 iOS 6上工作)

  显示原文与译文双语对照的内容

以下代码无法在 iOS 5和 iOS 5.1 ( 但适用于 iOS 6 ) 上运行:


- (void)viewDidLoad {
. . .
 UILongPressGestureRecognizer* gesture = [[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)] autorelease];
 [myWebView addGestureRecognizer:gesture];
}

- (void)handleLongPress:(UIGestureRecognizer*)gestureRecognizer {
. . .
}

如何修复问题? 感谢你的帮助 !

时间:

正确的代码:


- (void)viewDidLoad {
 UILongPressGestureRecognizer* gesture = [[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)] autorelease];
 gesture.delegate = self;
 [myWebView addGestureRecognizer:gesture];
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
 return YES;
}

试试这个代码。


 UILongPressGestureRecognizer *longpressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressHandler:)];
 longpressGesture.minimumPressDuration = 5;
 [longpressGesture setDelegate:self];
 [myWebView addGestureRecognizer:longpressGesture];
 [longpressGesture release];

 - (void)longPressHandler:(UILongPressGestureRecognizer *)gestureRecognizer {
 NSLog(@"longPressHandler");
 }

...