samedi 18 juin 2016

how to swap view controllers correctly when orientation changes

My app has two view controllers one Portrait and one Landscape. When orientation changes, I want to show controller as per orientation.

As suggested by Apple at link below, I try to put LandscapeViewController on top of PortraitViewController when device orientation changes to landscape and dismiss it when back to portrait. Apple example use storyboard and I dont.

I have one issue I am unable to resolve for sometime.

In PortraitViewController I have this

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

In LandscapeViewController, I have this

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

When device orientation goes from Portrait ---> Landscape, the portrait view does not rotate because of code above.

But that leads to issue that LandscapeViewController appears with portrait dimensions. Meaning it takes only half of screen in Landscape mode.

If I remove following code from PortraitViewController

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

Then LandscapeViewController controller appears correctly but in that case PortraitViewController autoRotates when orientation changes and takes only half of screen in Landscape mode. Which does not look good.

How can I fix this issue?

https://developer.apple.com/library/ios/samplecode/AlternateViews/Listings/ReadMe_txt.html#//apple_ref/doc/uid/DTS40008755-ReadMe_txt-DontLinkElementID_22

Aucun commentaire:

Enregistrer un commentaire