当应用程序启动时,我的项目中有一个介绍电影,我正在使用storyboard
,然后我将我MovieVC
作为初始视图,所以当应用程序启动时,MovieVC
当你按下或电影结束时,它会显示呈现RootVC
. 它在我测试它时工作simulator
,device
但是当我用instruments
using测试它时Leaks
,发现内存泄漏。
我不知道出了什么问题,我正在使用 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];
}
希望有人会帮助我做错了什么。谢谢你。