在uiwebview中添加长按手势,
UILongPressGestureRecognizer* longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
[self.webView addGestureRecognizer:longPress];
longPress.delegate = self;
longPress.cancelsTouchesInView = NO;
在 方法 handleLongPress中处理 长按消息
-(void)handleLongPress:(UITapGestureRecognizer *)sender
{
[self.webView removeGestureRecognizer:sender];
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle: nil
delegate:self
cancelButtonTitle:NSLocalizedString(@"取消", nil)
destructiveButtonTitle:nil
otherButtonTitles:NSLocalizedString(@"保存", nil),nil];
[actionSheet showInView:self.view];
}
因为没有从视图中移除长按手势,造成UIActionSheet点击出错,第1次点击进入委托方法,但是按钮没有选中,第2次选中,又进一次委托,造成UIActionSheet无法单击按钮关闭,并且响应委托方法。
问题重点:
[self.webView removeGestureRecognizer:sender];