我想要检测UIWebView tap的UILongPressGestureRecognizer -并按住..such键,当我长按近3秒时,下面的if条件应该是True then only
每次..does不检查longPressGesture时间时,循环中都会继续执行if (navigationType == UIWebViewNavigationTypeLinkClicked && longGesture ),但不是working....it ...
就连我也试过这种情况..
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;
}发布于 2013-02-04 20:14:57
您应该启用同步手势识别,因为UIWebView本身设置了一些识别器,您的识别器将被跳过:在代码中添加以下内容
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}发布于 2013-02-04 20:48:44
你没有为你的手势识别器设置目标动作,是吗?
UILongPressGestureRecognizer *longGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressGestureUpdated:)];设置一个目标动作将让你得到通知,无论手势是否触发!我将从这种方法开始,首先检查是否调用了"longPressGestureUpdated“方法。
试试下面的定义:
longPGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressGestureUpdated:)];
longPressGesture.numberOfTouchesRequired = 1;
longPressGesture.delegate = self;
longPressGesture.cancelsTouchesInView = NO;(并按照MilKyWaY的建议启用同步手势识别)
发布于 2013-02-05 14:49:18
- (void)viewDidLoad
{
[super viewDidLoad];
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(handleLongPress:)];
longPress.numberOfTouchesRequired = 1;
[self.view addGestureRecognizer:longPress];
}
-(void)handleLongPress:(UILongPressGestureRecognizer *)gesture
{
if (gesture.state == UIGestureRecognizerStateBegan)
{
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];
}
}https://stackoverflow.com/questions/14686406
复制相似问题