我已将WebView放置在Scrollview中,而Scrollview又放置在viewcontroller的视图中。 点击webview时,“tapRecognized”方法不会被调用。
这是我的代码:
UITapGestureRecognizer *oneFingerTwoTaps =
[[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapRecognized)] autorelease];
[oneFingerTwoTaps setNumberOfTapsRequired:1];
// Add the gesture to the view
[[self view] addGestureRecognizer:oneFingerTwoTaps];
我也尝试过使用foll:
[scrollview addGestureRecognizer:oneFingerTwoTaps];
[webview addGestureRecognizer:oneFingerTwoTaps];
请帮忙
答案 0 :(得分:5)
尝试添加以下语句:
//.h
...
@interface yourclass <UIGestureRecognizerDelegate>
...
//.m
...
[oneFingerTwoTaps setDelegate:self];
...
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
我希望它可以提供帮助
答案 1 :(得分:0)
手势识别器只能添加到单个视图中。视图无法共享手势识别器。虽然UIViews可以附加多个手势识别器,但UIGestureRecognizer只能附加一个视图。当您将Gesture添加到任何基于UIView的视图时,以下是在UIGestureRecognizer上设置的属性。
view
The view the gesture recognizer is attached to. (read-only)
@property(nonatomic, readonly) UIView *view
Discussion
You attach (or add) a gesture recognizer to a UIView object using the addGestureRecognizer: method.
Availability
Available in iOS 3.2 and later.
Declared In
UIGestureRecognizer.h