How to Rotate Viewcontroller Manually?

Asked

Viewed 35 times

0

I started a project, where I use a Custonnavigationcontroller to control the navigation of the screens.

In this project, only one viewcontroller can be rotated to Landscape mode. But the following problem occurs, thus:

1 - Start the app on Portrait 2 - I navigate to the screen 3 - I rotate the device and the screen goes into Landscape mode 4 - Keeping the app in Landscape mode, back to the previous screen, the app continues in Landscape and non-rotational to Portrait.

In other words: In Customnavigationcontoller, I determined that only 1 screen could be rotated to Landscape mode. However, when returning the previous screen the orientation is maintained in Landscape mode.

How could you rotate the screen that is in Landscape to to Portrait before it is removed?

I tried to use the code below, but without success:

-(void)viewWillDisappear:(BOOL)animated{

    if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) ||
        ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)) {

        NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
        [[UIDevice currentDevice] setValue:value forKey:@"orientation"];

    }
}
  • 1

    Guys, it was easier to do the project autolayout, than to do it :D but I will keep the question for didactic questions

1 answer

-1

Try it this way.

 
#define degreesToRadians(x) (M_PI * x / 180.0)

self.view.transform = CGAffineTransformRotate(self.view.transform, degreesToRadians(-90));
  • Apparently the goal is to modify the orientation of the screen and not rotate the view. Rotating the view is not a good idea because push notification, dialogs, and other similar components will continue in the opposite orientation of the rotated view and usability will be compromised.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.