iphone - UILongPressGestureRecognizer 不工作

标签 iphone ios uiwebview uigesturerecognizer

我想检测 UIWebViewUILongPressGestureRecognizer 点击并按住 .. 这样当我长按将近 3 秒时,下面的 if 条件应该是 True 那么只有
if (navigationType == UIWebViewNavigationTypeLinkClicked && longGesture ) 但它不起作用....它每次都在循环中继续..不检查 longPressGesture 时间...

即使我已经尝试过这种情况..

if (navigationType == UIWebViewNavigationTypeLinkClicked && longGesture.minimumPressDuration> 3 )

不工作..我哪里出错了..

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{


UILongPressGestureRecognizer *longGesture = [[UILongPressGestureRecognizer alloc] init];

longGesture.numberOfTapsRequired = 1;
longGesture.numberOfTouchesRequired = 1;
longGesture.minimumPressDuration = 3
;
longGesture.delegate = self;
// longGesture.allowableMovement = 50;

[self.webView addGestureRecognizer:longGesture];



if (navigationType == UIWebViewNavigationTypeLinkClicked  && longGesture )
{
    // Call your custom actionsheet and use the requestURL to do what you want :)


    UIActionSheet *sheet = [[UIActionSheet alloc]
                            initWithTitle:@" OPTIONS "
                            delegate:self
                            cancelButtonTitle:nil
                            destructiveButtonTitle:nil
                            otherButtonTitles:nil];


    [sheet addButtonWithTitle:@"Open"];
    [sheet addButtonWithTitle:@"Copy"];

    // Set cancel button index to the one we just added so that we know which one it is in delegate call
    // NB - This also causes this button to be shown with a black background
    sheet.cancelButtonIndex = sheet.numberOfButtons-1;

    [sheet showInView:webView];
    return NO;
  }

最佳答案

您应该启用同步手势识别,因为 UIWebView 本身设置了一些识别器,您的被跳过了: 将此添加到您的代码中

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

关于iphone - UILongPressGestureRecognizer 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14686406/

相关文章:

iphone - 关于我的 OpenGL 的问题 - 代码

ios - 如何使用不同的特征删除 View ?

ios - 如何在 iOS 中使用共享表共享文件?

iphone - UIWebView 没有使用 ARC 释放所有事件字节

iphone - UITableView 的自动布局错误

ios - 如何在应用程序内购买功能中以编程方式更改产品价格?

iphone - 在 Objective-C (iOS) 中测试内存管理

ios - 是否可以检测 iPhone 何时打开?

ios - 正在主线程上执行长时间运行的操作。 swift

ios - webview 不显示在 iphone 6 的全屏上