5

我已将 WebView 放置在 Scrollview 中,而后者又放置在 viewcontroller 的视图中。点击 web 视图时,不会调用“tapRecognized”方法。

这是我的代码:

    UITapGestureRecognizer *oneFingerTwoTaps = 
      [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapRecognized)] autorelease];

    [oneFingerTwoTaps setNumberOfTapsRequired:1];


// Add the gesture to the view

[[self view] addGestureRecognizer:oneFingerTwoTaps];

我也尝试过以下方法:

[scrollview addGestureRecognizer:oneFingerTwoTaps];

[webview addGestureRecognizer:oneFingerTwoTaps];

请帮忙

4

2 回答 2

5

尝试添加以下语句:

//.h
...
@interface yourclass <UIGestureRecognizerDelegate>
...

//.m
...
[oneFingerTwoTaps setDelegate:self];
...

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    return YES;
}

我希望它可以帮助

于 2012-04-15T12:43:45.083 回答
0

手势识别器只能添加到单个视图中。视图不能共享手势识别器。虽然 UIView 可以附加多个手势识别器,但 UIGestureRecognizer 只能附加一个视图。这是当您将手势添加到任何基于 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
于 2012-04-15T13:07:55.700 回答