简体   繁体   English

自定义动画后的UIButton操作

[英]UIButton action after custom animation

I want to have custom animation conected with UIButton, so I have decided to create own class with superclass UIButton. 我想使用UIButton连接自定义动画,因此我决定使用超类UIButton创建自己的类。 Then i overloaded touchesBegan method like that 然后我像这样重载了touchesBegan方法

-(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];
                          }];}

Animation works fine but nothing happen after. 动画效果很好,但是之后什么也没发生。 It looks like calling super method doesnt work in completion handler (dont know why). 看来调用super方法在完成处理程序中不起作用(不知道为什么)。 My question is: what can I change to have delayed UIButton action creating own class in similar way ? 我的问题是:我应该如何更改以类似的方式延迟UIButton创建自己的类的动作?

EDIT: I want to create own class because i have a lot of buttons in my app and i want them to behave the same. 编辑:我想创建自己的类,因为我在我的应用程序中有很多按钮,我希望它们的行为相同。

通常将UIButton操作分配给在UIControlEventTouchUpInside上触发,这应该在touchesEnded方法而不是touchesBegan中解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM