我有 UIWebView 用于显示文章。这些都是 HTML 页面。我需要从文章中选择文本。所以,我使用 UIMenucontroller 来选择选项。我需要在用户点击 singleTap 时选择文本。但是当使用 singleTap 时什么也没有发生。
-(void)ViewDidLoad{
UITapGestureRecognizer *singletapp=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(singleTap:)];
singletapp.numberOfTapsRequired=1;
[wbCont addGestureRecognizer:singletapp];
}
单击:
-(void)singleTap:(UIGestureRecognizer *)gestureRecognizer
{
NSLog(@"single tap");
CGPoint touchPoint = [gestureRecognizer locationInView:self.view];
NSString *js = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).toString()", touchPoint.x, touchPoint.y];
NSString * tagName = [wbCont stringByEvaluatingJavaScriptFromString:js];
NSLog(@"Selected Name: %@",tagName);
}