我知道这是一个常见问题,但似乎找不到适合我需求的正确解决方案。
确定,我有一个UIViewController(其父视图是UINavigationController,然后是UITabBarController)必须处于纵向模式。这个人可以模态显示另一个- (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];
}
为了返回第一个视图控制器,我使用了这些代码段
- (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];
}
}
是由第二个视图控制器在旋转设备时生成的。为什么?警告
谢谢
我知道这是一个常见问题,但似乎找不到适合我需求的正确解决方案。好的,我有一个UIViewController(该父视图是一个UINavigationController,然后是一个...
Warning: Attempt to present ViewController on TabBarController whose view is not in the window hierarchy
。此警告是因为当您从视图控制器中不在视图中的push:
或present:
出现viewController
时。意味着您的第一个视图控制器尚未加载或未完全显示,但是您正在从该ViewController中呈现或推送另一个。