LongPress手势在iOS 5和iOS 5.1上不起作用(但适用于iOS 6)

时间:2012-11-09 02:51:01

标签: iphone ios ipad gestures

以下代码在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 {
  ...
}

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

2 个答案:

答案 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");
    }