2011-04-23 60 views
0

我有一個觀點產生這樣的:iPhone - 我怎麼可能趕上一個接進一個UIWebView或一個UIImageView

oneView = [[UIView alloc] initWithFrame:CGRectMake(x, y , w, h)]; 
oneView.tag = i; 

UITapGestureRecognizer* recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap2:)]; 
[recognizer setNumberOfTouchesRequired:1]; 
[oneView addGestureRecognizer:recognizer]; 
recognizer.delegate = self; 
[recognizer release]; 

- (void)handleSingleTap2:(UITapGestureRecognizer *)recognizer { 
    int viewID = recognizer.view.tag; 
    NSLog(@"id : %d", viewID); 
} 

這工作,但如果我有一個UIWebView或UIImageView的頁頭,然後更換了UIView ALLOC觸摸事件不再被觸發。

我該如何讓它工作?

回答

0

集userInteractionEnabled = YES,如果需要multipleTouchEnabled = YES

+0

默認情況下,webview將這兩個屬性設置爲yes,否則您將無法使用瀏覽器。 – 2011-04-23 13:10:27

+0

不適用於UIWebView。 – Oliver 2011-04-23 13:11:16

0

必須覆蓋

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;

委託功能和返回YES;