Using Uiinterfaceorientation to change screen

Asked

Viewed 66 times

0

I need to know how to change the iPhone screen when it’s rotated (From Portrait to Landscape).

For example, when he is in Portrait mode he presents Screen A, when he is in Left Landscape he presents screen B and when he faces Right Landscape screen C.

That is, that it fires the method presentViewController:animated:completion: when the screen orientation change occurs, or some other method that is specific to this behavior.

Thank you.

1 answer

1


You can do it by the method:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

Before the interface orientation is changed, check which orientation the application will go to and present the corresponding Viewcontroller.

It’ll be something like this:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {

        // Do Something

    } else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {

        // Do Something    

    } else if (toInterfaceOrientation == UIInterfaceOrientationPortrait) {

        // Do Something
    }
}
  • Thank you! I will test and bring you the answer!!

  • Your answer was very helpful... but now the direction is another... I was asked this solution in Swift :P

Browser other questions tagged

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