我想将自定义动画与UIButton连接,所以我决定使用超类UIButton创建自己的类。然后我超载触摸开始这样的方法
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[UIView animateKeyframesWithDuration:0.5
delay:0
options: 0
animations:^{
[UIView addKeyframeWithRelativeStartTime:0
relativeDuration:0.5
animations:^{
self.transform = CGAffineTransformScale(self.transform, 0.7, 0.7);
}];
[UIView addKeyframeWithRelativeStartTime:0.5
relativeDuration:0.5
animations:^{
self.transform = CGAffineTransformIdentity;
}];
}
completion:^(BOOL finished) {
[super touchesBegan:touches withEvent:event];
}];}
动画工作正常,但之后什么也没发生。看起来调用超级方法在完成处理程序中不起作用(不知道为什么)。我的问题是:我可以更改什么以延迟 UIButton 操作以类似的方式创建自己的类?
编辑:我想创建自己的类,因为我的应用程序中有很多按钮,我希望它们的行为相同。
UIButton 操作通常被分配在 UIControlEventTouchUpInside 上触发,这应该在 touchesEnd 方法中解决,而不是 touchesBegin 中。