Making an animation to expand and shrink an UIView

后端 未结 3 797
伪装坚强ぢ
伪装坚强ぢ 2020-12-28 14:49

I want to create an animation that will resize an UIView and its contents by a factor. Basically, I want to make an animation that first expands the view then shrinks it bac

3条回答
  •  萌比男神i
    2020-12-28 15:12

    Here is a smaller approach that also loops:

    [UIView animateWithDuration:1
                          delay:0
                        options:UIViewKeyframeAnimationOptionAutoreverse | UIViewKeyframeAnimationOptionRepeat
                     animations:^{
                         yourView.transform = CGAffineTransformMakeScale(1.5, 1.5);
                     }
                     completion:nil];
    

    The option UIViewKeyframeAnimationOptionRepeat is what makes it loop, if you don't want it to keep "breathing". The animation block acts as the "inhale" and the UIViewKeyframeAnimationOptionAutoreverse option automatically plays the "exhale" animation.

提交回复
热议问题