我希望我的应用程序以纵向显示,但用户可以在某些ViewControllers中手动更改界面方向。
MyNavigationVC - >以纵向推VC1 - >以纵向推送VC2默认 - >按一个按钮切换到横向。
因此,我在.plist文件中检查设备方向为portrait, landscape left, landscape right
。在最顶级的NavigationController中,我已经覆盖了这样的方法:
//MyNavigationVC : UINavigationController
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
假设我希望VC1始终以纵向显示,并且默认情况下以纵向推送VC2,但用户可以按FullScreen
按钮切换到横向。所以,我在按钮操作中更改了状态栏的方向:
- (void)onFullScreenButtonTouchUpInside:(id)sender
{
[self changeViewFrameToFullScreen];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
}
在iOS 8上,状态栏处于横向状态,但键盘将以纵向显示。仅当用户手动将设备转为横向(并且界面方向也是横向)时,键盘才会以横向显示。
这是iOS 8的错误吗?我该怎么办才能修好它?感谢。
答案 0 :(得分:3)
此代码可以解决问题:
- (void)onFullScreenButtonTouchUpInside:(id)sender
{
[self adjustViewFrameToFullScreen];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
//change the device orientation
if (IsIOS8) {
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeLeft] forKey:@"orientation"];
}
}
答案 1 :(得分:0)
我遇到了类似的问题,以下问题解决了这个问题:
// Note that UIInterfaceOrientationLandscapeLeft is equal to UIDeviceOrientationLandscapeRight (and vice versa).
// This is because rotating the device to the left requires rotating the content to the right.
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeLeft] forKey:@"orientation"];