4

mostly I want my app show in portrait, but the user can manually change the interface orientation in some ViewControllers.

MyNavigationVC -> push VC1 in portrait -> push VC2 in portrait default -> press a button to switch to landscape.

So, I check device orientation to portrait, landscape left, landscape right in .plist file. And in the top-most NavigationController, I have override the method like this:

//MyNavigationVC : UINavigationController
- (BOOL)shouldAutorotate
{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

Assuming that I want VC1 show in portrait always, and Push VC2 in portrait by default, but user can press FullScreen button to switch to landscape. So, I changed the status bar's orientation in the button action:

- (void)onFullScreenButtonTouchUpInside:(id)sender
{
    [self changeViewFrameToFullScreen];
    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
}

Everything is ok on iOS6/7, But not iOS8.

The orientation of the keyboard on iOS 8 is not the same as status bar.

On iOS 8, the status bar is in landscape, but the keyboard will show in portrait. Only if the user turn the device to landscape manually(and the interface orientation is also in landscape), then the keyboard will show in landscape.

Is this a bug of iOS 8? What could I do to fix it? Thanks.

LessFun
  • 399
  • 3
  • 11
  • Did you add `Launch screen interface file base name` key to `Info.plist` file as discussed [here](http://stackoverflow.com/a/26899332/2066428)? – malex Nov 13 '14 at 01:05

2 Answers2

3

This code could fix the problem:

- (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"];
    }
}
LessFun
  • 399
  • 3
  • 11
0

I had a similar problem and the below does fix it:

// 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"];
Emmo213
  • 87
  • 5