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;
}