gpt4 book ai didi

ios - UIButton 不响应触摸事件

转载 作者:行者123 更新时间:2023-11-28 23:30:07 25 4
gpt4 key购买 nike

我有一个 UIButton 不响应触摸事件。并且按钮只有一些不处理事件的 subview 。所以我用我定制的 UIButton 替换它来看看发生了什么。下面是我的代码:

@interface CustomButton : UIButton

@end

@implementation CustomButton

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event];
}

-(BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
{
return [super beginTrackingWithTouch:touch withEvent:event];
}
@end

我发现调用了 touchesBegan:withEvent: 方法,但从未调用过 beginTrackingWithTouch:withEvent:。看来该事件已被分派(dispatch)到我的按钮,但我不明白为什么该事件从未被跟踪。任何线索将不胜感激。

最佳答案

禁用按钮上方未监听事件的 View 的用户交互。检查按钮是否启用了用户交互。检查 UIButton 的框架大小,并确保在以编程方式使用自动布局时它不为零。

关于ios - UIButton 不响应触摸事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56891391/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com