0
我有一个电影的介绍在我的项目时,应用程序启动时,我使用storyboard
顺便说一下,然后我让我MovieVC
作为初始视图,因此当应用程序启动时,显示的MovieVC
那么当您按下或电影结束,它将显示RootVC
。它在simulator
和device
中工作,当我测试它时,但是当我使用Leaks
与instruments
进行测试时,发现了内存泄漏。avplayer内存泄露
我不知道什么是错,我使用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];
}
希望有人会帮上什么,我做错了。谢谢。
在viewDidLoad方法的顶部添加[super viewDidLoad]并删除不需要的[super viewDidLoad]行,因为你已经使用了两次。 –
您能更具体地了解仪器泄露的内容吗? –
@CarlVeazey我已经使用'Leaks',这是我的另一个问题连接到这个---> http://stackoverflow.com/questions/12581164/detecting-fixing-memory-leaks – Bazinga