Core Animation Image sequence

前端 未结 1 2030
野趣味
野趣味 2021-02-04 21:35

How would i go about creating an image sequence with core animation. I would like to:

add image1 for 1 second then remove image

add image2 for 2 seconds then rem

相关标签:
1条回答
  • 2021-02-04 22:05

    The easiest way is to use CABasicAnimation for contents key:

    CABasicAnimation *animation = [CABasicAnimation animation];
    animation.fromValue = (id)[UIImage imageNamed:@"image1.png"].CGImage;
    animation.toValue = (id)[UIImage imageNamed:@"image2.png"].CGImage;
    animation.duration = 1.0f;
    animation.repeatCount = HUGE_VAL;
    //  animation.autoreverses = YES;
    [image1Layer addAnimation:animation forKey:@"contents"];
    

    This animation will infinitely change the layer contents between image1 and image2. You may want to set autoreverses property for smoother transitions - test animation either ways and choose the option you like the best.

    0 讨论(0)
提交回复
热议问题