Method for animating images (like a movie) on iPhone without using MPMoviePlayer

前端 未结 3 1409
攒了一身酷
攒了一身酷 2020-11-27 06:24

I need to be able to display an animation over a static image.

Given that MPMoviePlayer gives you no control over anything useful, the only way I can think to do t

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 07:10

    As you have discovered, using UIImageView.animationImages does not work because it uses up all your system memory and will crash your app. You could use a timer and set the image property of the UIImageView each time the timer fires, the UIImage object you use as the contents would need to be loaded each time the timer fires. That is basically the same as the approach described in the other answer, except that it uses CALayer instead of UIImageView. Loading an image and changing the image contents each time the timer fires is an okay approach, but it will only be able to get your about 11 FPS on an iPhone for full screen images.

    If you would like to use a working example that implements the UIImageView switching logic, then download this PNG Animation example project for xcode. I also provide the AVAnimator library, an optimized version of the same sort of functionality, it supports Quicktime Animation and APNG formats as well as compression.

提交回复
热议问题