我想檢測UILongPressGestureRecognizer
爲UIWebView
分接開關不放..such,當我長按近3秒鐘,然後下面的if
條件應該是True
那麼只有
if (navigationType == UIWebViewNavigationTypeLinkClicked && longGesture)
但它不工作... 。它繼續在迴路每次..does爲longPressGesture不及時檢查...UILongPressGestureRecognizer不工作
即使我已經與條件試過..
if (navigationType == UIWebViewNavigationTypeLinkClicked && longGesture.minimumPressDuration> 3)
不working..where我會犯錯..
- (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;
}
沒有不工作的男人! – Christien
意味着如果我使用'longGesture.minimumPressDuration = 3' ;和'if(navigationType == UIWebViewNavigationTypeLinkClicked && longGesture.minimumPressDuration)'它使if條件爲TRUE而不保持3秒 – Christien
@MilKyWaY - 我在幾個月前遇到了一個問題,我努力讓LongTouch使用普通的觸摸識別器 - 並且最終放棄了而不是使用longtouch,因爲我認爲兩者都是不可能的。然後我看到這個。非常感謝你。 –