如何从uiwebview或self.view中检测点击手势?
问题描述:
大家好,我使用以下代码查看了uitapgesture:
Hello everyone I have a uitapgesture on my view using the following code :
UITapGestureRecognizer *tap= [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(TAPGestureRecognizer)];
tap.numberOfTapsRequired=1;
tap.delegate = self;
[self.view addGestureRecognizer:tap];
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
我的UIview中有一个uiwebview作为子视图.问题在于在uivewview HTML上它具有onclick();.反过来就是所谓的手势.有帮助吗?
And I have a uiwebview as a subview in my UIview. The problem is that on the uivewview HTML it had a onclick(); which in turn is calling the tapgesture. Any help?
答
FirstView.image=[UIImage imageNamed:@"shape1.jpg"];
FirstView.tag=1;
FirstView.userInteractionEnabled=YES;
[FirstView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(firstimagetouch:)]];
SecondWebView.tag=2;
SecondWebView.userInteractionEnabled=YES;
[SecondWebView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(firstimagetouch:)]];
-(void)firstimagetouch:(UIGestureRecognizer *)sender
{
UIView * view=sender.view;
NSLog(@"%ld",(long)view.tag);
}
尝试这种方式,首先添加手势识别器进行查看,然后根据给他的标签值和获取标签值的web视图.并做你想做的事.
try like this first add gesture recognizer to view and then your webview according to give him tag value and get tag value. and do what you want.