我知道这是一个常见问题,但我似乎找不到适合我需要的正确解决方案。
好的,我有一个 UIViewController(它的父 View 是一个 UINavigationController,然后是一个 UITabBarController)被迫处于纵向模式.这家伙有能力以模态方式呈现另一个 UIViewController,当用户旋转设备时,它被迫保持横向模式。我决定使用手动转场来展示最后一个人。 这是演示文稿的代码:
- (void)viewDidAppear:(BOOL)animated {
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (void)orientationChanged:(NSNotification *)notification {
// Respond to changes in device orientation
if (UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation])) {
[self performSegueWithIdentifier:@"gallerySegue" sender:self];
}
}
-(void) viewDidDisappear {
// Request to stop receiving accelerometer events and turn off accelerometer
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
}
为了返回到第一个 View Controller ,我使用了这些代码
- (void)viewDidAppear:(BOOL)animated {
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(returnBack:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
-(void) viewDidDisappear {
// Request to stop receiving accelerometer events and turn off accelerometer
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
}
- (void)returnBack:(NSNotification *)notification {
// Respond to changes in device orientation
if (UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation])) {
[self dismissViewControllerAnimated:NO completion:nil];
}
}
当我旋转设备时,第二个 View Controller 会生成警告。
为什么??
谢谢
最佳答案
Warning: Attempt to present ViewController on TabBarController which view is not in the window hierarchy
。这个警告是因为当你push:
or present:
viewController 中的 viewController
不在 View 中。意思是您的第一个 View Controller 尚未加载或完全显示,但您正在展示或推送另一个 View Controller 。
关于ios - 警告 : Attempt to present ViewController on TabBarController whose view is not in the window hierarchy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25055741/