[英]Warning about window hierarchy
我的調試器中有這樣的警告,這是什么意思?
Warning: Attempt to present <RootViewViewController: 0x134ce9c0> on <MovieViewController: 0xa967290> whose view is not in the window hierarchy!
我還將MovieViewController
作為Storyboard中的初始視圖控制器,我也使用ARC。
注意:當我添加兩個[super viewDidLoad];
時,這不會出現[super viewDidLoad];
在viewDidLoad
最低部分中間1,這是錯誤的。
這是我對MovieViewController
實現:
- (void)viewDidLoad
{
[super 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];
[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];
}
- (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];
}
幫助將不勝感激:)
當ViewController的view
加載到內存中時,將調用viewDidLoad
方法。 但到那時, view
還沒有在屏幕上顯示(因此它沒有被添加為任何其他view
或window
的subview
,也就是說它不在視圖層次結構中)。
您應該等待視圖在屏幕上顯示您的MovieViewController
。 移動你的代碼在viewDidAppear:
方法和viewDidLoad
,你應該沒問題。
viewDidLayoutSubviews
可用於此目的。 它早於viewDidAppear。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.