我想检测UILongPressGestureRecognizer
为了UIWebView
点击并按住..这样当我长按近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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)