以下代码在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 {
...
}
如何解决问题?非常感谢您的帮助!
答案 0 :(得分:1)
正确的代码:
- (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;
}
答案 1 :(得分:0)
试试这段代码..
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");
}