好的 固定的。
使用 UINavigationController,当我 popToViewController:animated: 从横向视图到纵向视图时,目标视图显示正确,但状态栏和 UIKeyboard 保持横向配置,造成真正的混乱。
解决
有关 statusBarOrientation 和参考的数千条建议阅读...
https://developer.apple.com/library/content/releasenotes/General/RN-iOSSDK-6_0/index.html
“setStatusBarOrientation:animated: 方法并未完全弃用。它现在仅在最顶层全屏视图控制器的 supportedInterfaceOrientations 方法返回 0 时才有效。这使得调用者负责确保状态栏方向一致。” (感谢Vytis在这里)
statusBarOrientation 仅在 supportedInterfaceOrientations 返回 0 时才有效,所以......这给了我们一个猜测。
如果 statusBarOrientation 不符合预期,则返回一个零(如果始终返回 0,则视图不会旋转,因此:
// if deviceOrientation is A (so I expect statusbarOrientation A
// but statusbarOrientation is B
// return 0
// otherwise
// return user interface orientation for A
- (NSUInteger)supportedInterfaceOrientations {
UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation];
UIInterfaceOrientation statusBarOrientation =[UIApplication sharedApplication].statusBarOrientation;
if(deviceOrientation == UIDeviceOrientationPortrait || deviceOrientation == UIDeviceOrientationPortraitUpsideDown){
if(statusBarOrientation != UIInterfaceOrientationPortrait ||statusBarOrientation != UIInterfaceOrientationPortraitUpsideDown){
return 0;
}
}
// otherwise
return UIInterfaceOrientationMaskPortrait;
}
现在,在 viewDidAppear 中(相信我,即使收到键盘通知,我也会使用此调用:
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationPortrait;
超过 48 个工时。希望这会有所帮助,谢谢大家。