0

我有一个 UIButton 不响应触摸事件。而且该按钮只有一些不处理事件的子视图。所以我用我定制的 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:未被调用。似乎该事件已发送到我的按钮,但我不明白为什么从未跟踪过该事件。任何线索将不胜感激。

4

1 回答 1

1

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

于 2019-07-04T19:44:02.353 回答