【问题标题】:UIButton not responding to 'touchUpInside' but will respond to 'touchDown' fineUIButton 没有响应 'touchUpInside' 但会响应 'touchDown' 很好
【发布时间】:2012-06-13 17:09:54
【问题描述】:

在我的程序中,我有一个 UIButton 以编程方式声明为 UIVIewController 的属性。我已将其设置为在用户触发touchUpInside 事件时发送操作,如下所示:

[restartButton addTarget:self action:@selector(handleRestart) forControlEvents:UIControlEventTouchUpInside]; 其中restartButtonUIButton 的名称。

当我在forControlEvents 参数中输入UIControlEventTouchDown 时,它工作正常。但是,UIControlEventTouchUpInside 根本不起作用。有人知道这是为什么吗?

【问题讨论】:

  • 您是否有机会覆盖 touchesMovedtouchesEnded
  • 不,但是如果有办法让它发挥作用,这种方法更可取。
  • 您应该尝试使用UIControlEventTouchUpInside 使其以正常方式 工作。我只是问,因为这(压倒一切)可能是原因。

标签: objective-c ios uibutton human-interface uicontrolevents


【解决方案1】:

您可能需要查看restartButton.bounds。您可以简单地将其设置为零,从而导致UIControlEventTouchUpInside 永远不会发生。检查它的最佳方法是为图层添加边框。

[restartButton.layer setBorderWidth:1.0f];
[restartButton.layer setBorderColor:[UIColor redColor].CGColor];

别忘了#import <QuartzCore/QuartzCore.h>以上的工作

【讨论】:

  • 我刚试过,大小不是0。边框完全适合按钮周围。还有其他想法吗?
  • 您尝试过 TouchUpOutside 活动吗?
  • 这是我的问题。感谢您的建议。
【解决方案2】:

查看此问题并回答:https://stackoverflow.com/a/11667958/607730。父视图上有一个 UITapGestureReconizer,它拦截了 TouchUpInside 事件,但允许触摸甚至通过。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多