2012-01-18 33 views
0

所以我有一個帶有textfields形式的uiscrollview。我正在嘗試向背景添加動作,以便用戶在背景上輕擊時鍵盤會縮回。在不禁用uibuttons的情況下在uiscrollview中啓用backgroundTap

我能得到的backgroundTap收起鍵盤,但它禁用我的uibuttons:Detecting hits in UIScrollView while still letting it do it's thing

由於在第二個回答說我加入這個代碼到viewDidLoad中:

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backgroundTap:)]; 

[scrollView addGestureRecognizer: singleTap]; 

凡backgroundTap是

- (IBAction)backgroundTap:(id)sender 

這讓我在uiscrollview上使用backgroundTap撤回鍵盤,但是它禁用了我的cancelButton關閉窗體的模態視圖,並關閉發送HTTP Post的submitButton。

任何想法,爲什麼它禁用uibuttons?

回答

0

做了一些更多的搜索,找到了正確的答案!我只是發佈鏈接並在這裏回答,以防其他人首先發現。

UITapGestureRecognizer *singleTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap:)]; 

singleTapGestureRecognizer.numberOfTapsRequired = 1; 
singleTapGestureRecognizer.enabled = YES; 
singleTapGestureRecognizer.cancelsTouchesInView = NO; 
[tapableView addGestureRecognizer:singleTapGestureRecognizer]; 
[singleTapGestureRecognizer release]; 

乾杯, Ĵ

iOS5 UITapRecognizer for UIScrollView interfering with buttons. How to fix?

相關問題