gpt4 book ai didi

iphone - UILongPressGestureRecognizer 不工作

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:03:38 28 4
gpt4 key购买 nike

我想检测 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com