我有一个 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:
未被调用。似乎该事件已发送到我的按钮,但我不明白为什么从未跟踪过该事件。任何线索将不胜感激。