我已经创建了一个 webview 来显示 pdf,现在使用单击手势识别器我必须调用一些方法,但单击无法识别
我用过这个代码
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;
返回YES
?另外,请确保将点击手势的委托(delegate)设置为 self,以便正确接收消息。我刚刚在一个新项目中对此进行了测试,它确实有效。
编辑
不太确定您的动画开始和提交的用途 - 方法 setNavigationBarHidden:animated:
会自行动画。此外,从 iOS 4 开始,不鼓励使用这些动画定义 - 请考虑在 UIView
上使用基于 block 的动画。
对于您的导航 Controller ,您已经差不多完成了 - 实现如下所示的内容:
- (void)screenTappedTwice:(UITapGestureRecognizer *)sender
{
BOOL shouldHideNavBar = [self.navigationController isNavigationBarHidden] ? NO : YES;
[self.navigationController setNavigationBarHidden:shouldHideNavBar animated:YES];
}
关于iphone - iPhone 应用程序中网页 View 上的手势识别器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7416466/