在UIViewController中,加入协议UIGestureRecognizerDelegate,然后.m文件里加入以下代码:
UITapGestureRecognizer*singleTap =[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[self.view addGestureRecognizer:singleTap];
//这个可以加到任何控件上,比如你只想响应WebView,我正好填满整个屏幕
singleTap.delegate=self;
singleTap.cancelsTouchesInView =NO;
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
returnYES;
}
-(void)handleSingleTap:(UITapGestureRecognizer *)sender{
CGPoint point =[sender locationInView:self.view];
NSLog(@"handleSingleTap!pointx:%f,y:%f",point.x,point.y);
}