在uiscrollview中启用backgroundTap而不禁用uibuttons

时间:2012-01-18 18:45:48

标签: uiscrollview uibutton

所以我有一个带有文本字段形式的uiscrollview。我正在尝试向背景添加动作,以便当用户点击背景时键盘缩回。

我能够使用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?

1 个答案:

答案 0 :(得分: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?