这对我有用...
在我的案例中,目标视图显示正确,但状态栏和 UIKeyboard 保持横向配置,造成真正的混乱。
解决了数千条关于 statusBarOrientation 和参考的建议后阅读... https://developer.apple.com/library/ios/#releasenotes/General/RN-iOSSDK-6_0/_index.html
“setStatusBarOrientation:animated: 方法并未完全弃用。它现在仅在最顶层全屏视图控制器的 supportedInterfaceOrientations 方法返回 0 时才有效。这使得调用者负责确保状态栏方向一致。”
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;