iphone应用程序中web视图上的手势识别器
我已经创建了一个webview来显示pdf,现在使用单点击手势识别器,我必须调用一些方法,但单点击无法识别 我用过这个代码iphone应用程序中web视图上的手势识别器,iphone,objective-c,uiwebview,uigesturerecognizer,Iphone,Objective C,Uiwebview,Uigesturerecognizer,我已经创建了一个webview来显示pdf,现在使用单点击手势识别器,我必须调用一些方法,但单点击无法识别 我用过这个代码 UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 450,450)]; UITapGestureRecognizer *DoubleFingerDTap = [[UITapGestureRecognizer alloc]
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 450,450)];
UITapGestureRecognizer *DoubleFingerDTap = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(screenTappedtwice:)];
DoubleFingerDTap.numberOfTapsRequired = 1;
[webView addGestureRecognizer:DoubleFingerDTap];
[DoubleFingerDTap release];
方法调用
- (void)screenTappedtwice:(UIGestureRecognizer *)sender {
CGPoint tapPoint = [sender locationInView:sender.view.superview];
[UIView beginAnimations:nil context:NULL];
sender.view.center = tapPoint;
//Check the current state of the navigation bar...
//BOOL navBarState = [self.navigationController isNavigationBarHidden];
// Set the navigationBarHidden to the opposite of the current state.
// [self.navigationController setNavigationBarHidden:TRUE animated:YES];
[self.navigationController setNavigationBarHidden:YES animated:YES];
[UIView commitAnimations];
}
您是否尝试设置:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;
要返回是
?此外,确保将轻触手势的委托设置为self,以便正确接收消息。我刚刚在一个新项目中测试了它,它确实有效。
编辑 不太确定动画开始和提交的目的是什么-方法
setNavigationBarHidden:animated:
会自动设置动画。此外,在iOS 4以后的版本中,不鼓励使用这些动画定义-请改为在UIView
上使用基于块的动画
对于您的导航控制器,您几乎就在那里-实现如下内容:
- (void)screenTappedTwice:(UITapGestureRecognizer *)sender
{
BOOL shouldHideNavBar = [self.navigationController isNavigationBarHidden] ? NO : YES;
[self.navigationController setNavigationBarHidden:shouldHideNavBar animated:YES];
}
与此问题类似:我无法从您的上述链接获得所需的ans,,感谢您的ans,,我已在UITapGestureRecognitor操作中调用Screen TappedWice:method来隐藏导航栏,但它不起作用。您能帮我吗?有关mehod定义Screen TappedWice,请参阅我编辑的问题