UILongPressGestureRecognizer无法正常工作 [英] UILongPressGestureRecognizer not working

查看:72
本文介绍了UILongPressGestureRecognizer无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检测 UIWebView UILongPressGestureRecognizer 并按住..这样,当我长按近3秒钟时,下面的 if 条件应为 True ,然后仅
if(navigationType == UIWebViewNavigationTypeLinkClicked& longGesture),但是它不起作用....它每次都在循环中继续..不检查longPressGesture时间...

I want to detect UILongPressGestureRecognizer for the UIWebView tap- and hold ..such that When I long press for almost 3 seconds then the below if condition should be True then only
if (navigationType == UIWebViewNavigationTypeLinkClicked && longGesture ) but its not working....it continues in the loop for every time ..does not check for the longPressGesture time...

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

even I have Tried with the condition..

如果(navigationType == UIWebViewNavigationTypeLinkClicked& longGesture.minimumPressDuration> 3)

不工作..我在哪里犯错..

not working..where I am making mistake..

- (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本身会设置一些识别器,您的识别器将被跳过:将此添加到您的代码中

You should enable simultaneous gesture recognition because the UIWebView sets a few recognizers itself, yours are skipped : add this in your code

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

这篇关于UILongPressGestureRecognizer无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆