Forum Xamarin.iOS

Popping to Root View Controller does no honour Interface Orientation

DaveCarsonDaveCarson GBUniversity ✭✭✭

Ok - this has been driving me mad for hours. I've Googled and I have tried numerous approaches but I still cannot get to the bottom of this.

I have an application when all of the View Controllers need to be portrait only - except one, which can be portrait or landscape. Simple surely.

Well, I have subclassed the UINavigationController and overridden GetSupportedInterfaceOrientations to return the corresponding value from it's TopViewController. Each ViewController has also overridden the GetSupportedInterfaceOrientations method to return the appropriate UIInterfaceOrientationMask value.

That all works as I navigate through the application the portrait only views stay in portrait and the portrait/landscape view can indeed be rotated and behaves as expected.

If I rotate the device while on the 'mixed mode' view and then click on a button which takes be back on step (calling NavigationController.PopViewController) then the resulting view spins back to a portrait orientation - exactly what I expect and indeed what I want to happen.
But, if I click a button which takes me 'Home' (calling NavigationController.PopToRootController) then the resulting view remains in landscape orientation. If I rotate the device back to portrait and the view follows suit and once there is it locked in place - further rotation does nothing.

I have tried all manner of options of ShouldAutoRotate and PerformSelector with no joy (far from it in fact).

I have attached a simple project to demonstrate this. It contains a subclassed UINavigationController and three UIViewControllers , A, B and C.

A and B are portrait only while C allows Landscape. Click the buttons to navigate to ViewController C and then rotate the device. If you tap the 'Go to View Controller B' button the view will snap back to portrait, but if you tap the 'Go to View Controller A' button it will not.

Can someone please restore my sanity - what am I missing here?

Best Answers


  • DaveCarsonDaveCarson GBUniversity ✭✭✭

    Hi @adamkemp - thanks for your response which was detailed and informative as always.

    The app requirements are for each page to have a footer which contains Back, Home and Contact Us buttons. The main content of the app contains 'tiles' which the user taps to navigate to the required content, sometime the final content is a couple of layers deep within the navigation. At any point the user can tap 'Home' to go back to the main application page which contains the root navigation options.

    The existing approach is working fine until the client has requested that a view support rotation - and we are supposed to be submitting to Apple at the end of the month :-(

    I've previously used PresentViewController when displaying a UIAlertController but not considered using it as the basis for app navigation.

    Something to look at though but time is tight so I'll need to make a decision about whether to make these changes for the initial release.

  • DaveCarsonDaveCarson GBUniversity ✭✭✭

    I've updated the sample app to use ViewContollerA as the Window.RootViewController in the AppDelegate and replaced my calls to UINavigationController with PresentViewController(new ViewControllerX(), false, null); and all seems to be fine.
    When I get to ViewControllerC it will rotate to landscape while the others do not.

    So, navigating back down the 'stack' of presented View Controllers. Going back a level is simple enough - just a call to DismissViewController(false, null) and that's sorted. But what dismissing all the way back to the RootViewController?

    Currently I have it working fine by grabbing a reference to the AppDelegate.Window.RootViewController and calling DismissModalViewController(false);. According to the documentation this appears to be the correct approach but before I go through the app implementing this approach I'm wondering if this is the correct approach.

  • DaveCarsonDaveCarson GBUniversity ✭✭✭

    Thanks @adamkemp - I thought that DismissViewController just dismissed itself by sending a message to it's 'parent'. Tested with that in place and all works fine.

    Thanks again for the pointers :-)

Sign In or Register to comment.