当应用程序启动时,我的项目中有一个介绍影片,顺便说一句,我正在使用 storyboard
,然后我将 MovieVC
作为初始 View ,所以当应用程序启动时,会显示 MovieVC
,然后当您按下或电影结束时,它将显示 RootVC
。当我测试它时,它在模拟器和设备中工作,但是当我使用Leaks
使用instruments
测试它时,内存发现泄漏。
我不知道出了什么问题,我正在使用 ARC,但我认为我的 moviePlayer
没有发布,或者我的问题出在 ViewControllers
中。
这是我的 MovieVC
代码:
- (void)viewDidLoad
{
self.view.backgroundColor = [UIColor whiteColor];
NSString *moviePath = [[NSBundle mainBundle] pathForResource:@"gameopening" ofType:@"m4v"];
self.moviePlayer = [AVPlayer playerWithURL:[NSURL fileURLWithPath:moviePath]];
[self.moviePlayer play];
// Create and configure AVPlayerLayer
AVPlayerLayer *moviePlayerLayer = [AVPlayerLayer playerLayerWithPlayer:self.moviePlayer];
moviePlayerLayer.bounds = CGRectMake(0, 0, 1024, 768);
moviePlayerLayer.position = CGPointMake(515,385);
moviePlayerLayer.borderColor = [UIColor clearColor].CGColor;
moviePlayerLayer.borderWidth = 3.0;
moviePlayerLayer.shadowOffset = CGSizeMake(0, 3);
moviePlayerLayer.shadowOpacity = 0.80;
// Add perspective transform
[self.view.layer addSublayer:moviePlayerLayer];
[super viewDidLoad];
[self performSelector:@selector(loadingView) withObject:nil afterDelay:33.0];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
tapGesture.numberOfTapsRequired = 1;
[self.view addGestureRecognizer:tapGesture];
[super viewDidLoad];
}
- (void)handleTapGesture:(UITapGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateEnded) {
UIImageView *loadingView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
loadingView.image = [UIImage imageNamed:@"Load.png"];
[self.view addSubview:loadingView];
[self performSelector:@selector(mainV) withObject:nil afterDelay:2.0];
}
}
-(void)loadingView{
UIImageView *loadingView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
loadingView.image = [UIImage imageNamed:@"Load.png"];
[self.view addSubview:loadingView];
[self performSelector:@selector(mainV) withObject:nil afterDelay:2.0];
}
-(void)mainV {
moviePlayer = nil;
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"mainViewController"];
vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:vc animated:YES completion:NULL];
}
希望有人能帮助我解决我做错的事情。谢谢。
最佳答案
我建议尝试使用设备运行仪器...如前所述,库本身存在一些问题。 如果设备上的泄漏消失,那么您就可以开始了..:)
关于iphone - avplayer内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12595594/