直接在UIWebView添加手势是没有反应的。需要实现一个代理方法。
1.给webView添加手势
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handle)];
tap.delegate = self;
[webView addGestureRecognizer:tap];
2.遵守协议UIGestureRecognizerDelegate,实现代理方法
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
return YES;
}
3.点击事件的处理
-(void)handle{
// 打开自带浏览器
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.baidu.com"]];
}
网友评论