2013-05-09 74 views
0

我在我的scrollview中有一個imageview,並且爲我的uiscrollview添加了一個水龍頭手勢。 enter image description here關於uiscrollview中的水龍頭手勢

只有imageview區域可以響應輕擊手勢。

爲什麼當我設置滾動型的backgroudcolor財產,那麼整個滾動視圖可以響應雙擊手勢

這裏是我的代碼

UIImageView * imgview=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bizhi1.png"]];  
imgview.frame=CGRectMake(0, 140, 320, 200);  

UIScrollView * scrollview=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; 
[scrollview addSubview:imgview]; 

//when i set the backgroudcolor,then the whole scrollview can respond tap gesture 
//scrollview.layer.backgroundColor=[UIColor redColor].CGColor; 

//add a TapGesture for scrollview 
UITapGestureRecognizer * tapGesture=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(SwitchTabBarHidden)];  
[scrollview addGestureRecognizer:tapGesture]; 
[tapGesture release]; 

[imgview release]; 
[self.view addSubview:scrollview]; 
[scrollview release]; 
+1

你想只在兩個圖像視圖的手勢? – 2013-05-09 04:38:49

+0

只是想整個uiscrollview區域可以響應輕擊手勢。 – 2013-05-09 04:47:55

+0

請獲取觸摸位置座標 - (void)singleTapGestureCaptured :(UITapGestureRecognizer *)手勢 – Deepesh 2013-05-09 04:48:03

回答

2

我敢肯定,這個代碼是正確的,因爲我實現了這個代碼,並沒有必要設置的backgroundColor財產滾動視圖。

+0

好吧,我打算爲這個測試創建一個新項目。 – 2013-05-09 05:06:47

+0

你確定你可以...... – 2013-05-09 05:11:39

+0

發生了什麼我親愛的你有嗎? – 2013-05-09 05:20:21

1

確保userInteractionEnabled設置爲YES上的UIImageView。:

frame.userInteractionEnabled = YES; 
+0

嗨! Rushabh。即使我添加imgview.userInteractionEnabled = YES;,它仍然只有imageview區域可以響應輕擊手勢。 – 2013-05-09 04:45:56

相關問題