【问题标题】:Enabling backgroundTap in uiscrollview without disabling uibuttons在uiscrollview中启用backgroundTap而不禁用uibuttons
【发布时间】:2012-01-18 18:45:48
【问题描述】:

所以我有一个带有文本字段形式的 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 收回键盘,但它禁用了我的取消按钮,它关闭了表单的模式视图,以及发送 HTTP Post 的提交按钮。

任何想法为什么它会禁用 uibuttons?

【问题讨论】:

    标签: uiscrollview uibutton


    【解决方案1】:

    做了更多的搜索,找到了正确的答案!我会在这里发布链接并回答,以防其他人先发现。

    UITapGestureRecognizer *singleTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap:)];
    
    singleTapGestureRecognizer.numberOfTapsRequired = 1;
    singleTapGestureRecognizer.enabled = YES;
    singleTapGestureRecognizer.cancelsTouchesInView = NO;
    [tapableView addGestureRecognizer:singleTapGestureRecognizer];
    [singleTapGestureRecognizer release];
    

    干杯, J

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-23
      • 1970-01-01
      • 2014-09-14
      • 2019-07-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多