iOS digital multiple animation


A simple digital multiple animation using transparency and scaling

Implementation ideas

The code is clear

// Digital jumping animation
- (void)labelDanceAnimation:(NSTimeInterval)duration {
    CABasicAnimation *opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
    opacityAnimation.duration = 0.4 * duration;
    opacityAnimation.fromValue = @0.f;
    opacityAnimation.toValue = @1.f;

    CAKeyframeAnimation *scaleAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
    scaleAnimation.duration = duration;
    scaleAnimation.values = @[@3.f, @1.f, @1.2f, @1.f];
    scaleAnimation.keyTimes = @[@0.f, @0.16f, @0.28f, @0.4f];
    scaleAnimation.removedOnCompletion = YES;
    scaleAnimation.fillMode = kCAFillModeForwards;

    CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
    animationGroup.animations = @[opacityAnimation, scaleAnimation];
    animationGroup.duration = duration;
    animationGroup.removedOnCompletion = YES;
    animationGroup.fillMode = kCAFillModeForwards;

    [self.comboLabel.layer addAnimation:animationGroup forKey:@"kComboAnimationKey"];

Use an alpha with a transparency between 0 and 1, then scale it and add it to the animation group to realize it

Remember that it's best to remove the animation after it's finished, otherwise it may cause animation memory problems

Set italics here

self.comboLabel.font = [UIFont fontWithName:@"AvenirNext-BoldItalic" size:50];

It's obvious

Called when the last button is clicked

- (IBAction)clickAction:(UIButton *)sender {
    [self labelDanceAnimation:0.4];
    self.comboLabel.text = [NSString stringWithFormat:@"+  %tu",self.danceCount];

If you want to realize dozen animation, it's very simple. Just use the module of "dancecount% 10 = = 0"


This animation is more suitable for some live scenes

Access to iOS digital multiple animation Demo, add iOS development exchange group: 624212887, access to Demo, and more iOS technical information

Tags: iOS

Posted on Tue, 03 Dec 2019 04:38:17 -0800 by sobbayi