在UIButton IOS上创建一系列动画

时间:2015-07-20 04:29:37

标签: ios objective-c animation uibutton

我对IOS动画编程很陌生。 我想在UIButton上创建这样的动画:

  1. 首先在0.3秒内扩大,
  2. 然后在0.2秒内缩小恢复正常。
  3. 有人可以向我展示或引导我走向正确的方向吗?

2 个答案:

答案 0 :(得分:2)

示例代码:

[UIView animateKeyframesWithDuration:0.5 delay:0.0 options:UIViewKeyframeAnimationOptionRepeat animations:^{

    [UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.60 animations:^{
        myButton.transform = CGAffineTransformMakeScale(2.0, 2.0);
    }];
    [UIView addKeyframeWithRelativeStartTime:0.60 relativeDuration:0.40 animations:^{
        myButton.transform = CGAffineTransformIdentity;
    }];
    } completion:^(BOOL finished) {
    NSLog(@"Completed");
}];

答案 1 :(得分:0)

您也可以在其中使用原生动画脉冲。

var pulseAnimation:CABasicAnimation = CABasicAnimation(keyPath: "transform.scale");
        pulseAnimation.duration = 1.0;
        pulseAnimation.toValue = NSNumber(float: 1.5);
        pulseAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut);
        pulseAnimation.autoreverses = true;
        pulseAnimation.repeatCount = FLT_MAX;
        self.Outlet.layer.addAnimation(pulseAnimation, forKey: nil)