2012-04-15 16 views
4

我已經將WebView放置在滾動視圖內,而ScrollView又放置在視圖控制器的視圖內。 當在web視圖上點擊時,「tapRecognized」方法沒有被調用。點擊手勢識別器不適用於UIScrollView內的UIWebiew,它位於UIView內

這裏是我的代碼:

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]; 

請幫

回答

5

嘗試添加以下語句:

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

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

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

我希望它能幫助

+0

謝謝你解決了我的問題,但又出現了另一個問題。 滾動視圖裏面有textField&按鈕,當他們被挖掘我不想這個手勢申請他們。我應該爲嗎? – CoderSaru 2012-04-15 16:52:16

+0

如果你想讓你的事件只被webview觸發,添加webview TapRecognizer,因此不應該與按鈕交互...等 – WhiteTiger 2012-04-15 17:27:08

+0

thanx buddy ... :) – 2012-07-27 11:48:43

0

手勢識別器只能添加到單個視圖中。視圖不能共享手勢識別器。雖然UIViews可以連接多個手勢識別器,但UIGestureRecognizer只能連接一個視圖。當您將AddGesture添加到任何基於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 
相關問題