Ios 在UIImageVIew上使用动画图像的有效方法
我的应用程序中有一个15秒的动画,目前效率太低,无法运行,因为它使用了1.5GB的RAM 我是否错误地使用UIImageView的动画属性?也许有不同的解决办法。我只想让它循环一段时间 我可以对539张图像进行改进,使其更高效,但它们仍然需要视网膜大小等。目前为30fpsIos 在UIImageVIew上使用动画图像的有效方法,ios,objective-c,animation,uiimageview,Ios,Objective C,Animation,Uiimageview,我的应用程序中有一个15秒的动画,目前效率太低,无法运行,因为它使用了1.5GB的RAM 我是否错误地使用UIImageView的动画属性?也许有不同的解决办法。我只想让它循环一段时间 我可以对539张图像进行改进,使其更高效,但它们仍然需要视网膜大小等。目前为30fps - (void)viewDidLoad { [super viewDidLoad]; _animationFrames = [[NSMutableArray alloc] init]; for (
- (void)viewDidLoad {
[super viewDidLoad];
_animationFrames = [[NSMutableArray alloc] init];
for (long l = 0; l < 540; l++) {
NSString *frameNumber = [NSMutableString stringWithFormat:@"AnimationFrames-%04ld", l];
UIImage *frame = [UIImage imageNamed:frameNumber];
[_animationFrames addObject:frame];
}
UIImageView *animation = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
animation.animationImages = _tutorialFrames;
animation.animationDuration = 14;
[self.view addSubview: animation];
[animation startAnimating];
}
-(void)viewDidLoad{
[超级视图下载];
_animationFrames=[[NSMutableArray alloc]init];
用于(长l=0;l<540;l++){
NSString*frameNumber=[NSMutableString stringWithFormat:@“AnimationFrames-%04ld”,l];
UIImage*frame=[UIImage ImageName:frameNumber];
[_animationframesaddobject:frame];
}
UIImageView*动画=[[UIImageView alloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height)];
animation.animationImages=\u教程框架;
animation.animationDuration=14;
[self.view addSubview:动画];
[动画开始动画];
}
感谢评论,我发现我可以使用嵌入式电影而不是通过UIImageView播放动画,尽管我最终选择了AVPlayer而不是MPMoviePlayer
#import "VideoViewController.h"
@import AVFoundation;
@interface VideoViewController ()
@property (weak, nonatomic) AVPlayer *avPlayer;
@property (weak, nonatomic) AVPlayerLayer *avPlayerLayer;
@end
@implementation VideoViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self avPlayer];
[self.avPlayer play];
}
- (AVPlayer *)avPlayer {
if (!_avPlayer) {
NSURL *url = [[NSBundle mainBundle]
URLForResource: @"Video" withExtension:@"mp4"];
_avPlayer = [AVPlayer playerWithURL:url];
_avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:_avPlayer];
_avPlayerLayer.frame = self.view.layer.bounds;
[self.view.layer addSublayer: _avPlayerLayer];
_avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[_avPlayer currentItem]];
}
return _avPlayer;
}
- (void)playerItemDidReachEnd:(NSNotification *)notification {
AVPlayerItem *p = [notification object];
[p seekToTime:kCMTimeZero];
}
您是否没有能力渲染动画,然后只播放电影?然后你的应用程序中还有15秒的电影。这不会占用太多空间。我可以,但我不想走那条路。我希望动画看起来像应用程序的一部分,而不是一个视频窗口出现,然后播放。好的,我明白了。但是当您使用MPMoviePlayer(而不是控制器)时,您可以禁用(隐藏)所有控件。