0

以下代码不适用于 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 {
  ...
}

如何解决问题?非常感谢您的帮助!

4

2 回答 2

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;
}
于 2012-11-09T03:01:10.873 回答
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");
    }
于 2012-11-09T04:01:10.480 回答