privateson
privateson

Reputation: 387

Create a sequence of Animation on UIButton IOS

I am pretty new to IOS animation programming. I wanna create an animation like this on an UIButton:

  1. first scale up in 0.3 second,
  2. then scale down back to normal in 0.2 second.

Can some one show me or guide me to the right direction?

Upvotes: 0

Views: 500

Answers (2)

Parth Adroja
Parth Adroja

Reputation: 13514

You can also use native animation pulse in it.

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)

Upvotes: 0

Bhavin
Bhavin

Reputation: 27225

Sample Code :

[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");
}];

Upvotes: 2

Related Questions