0

I have an app where the user uses in portrait mode.

I have a gallery feature which I want to only work in landscape mode.

However my problem is that I have my orientations set as such so that all my views are in portrait.

enter image description here

How do I force one view to load in landscape?

And how would I do that view on my storyboard in landscape mode?

user3699052
  • 303
  • 4
  • 12
  • You can allow both "Portrait" and "Upside Down" device Orientation and then force the orientation in a programmatically way. But I am not sure it is a good practice in term of `User eXperience` aspect: you shouldn't force your user to rotate its device, especially if you don't allow him to do it in the rest of your application. – sebastien FCT Jul 06 '14 at 02:35
  • How do I force it programmatically? – user3699052 Jul 06 '14 at 02:36
  • First of all by searching on SO ;) http://stackoverflow.com/questions/9826920/uinavigationcontroller-force-rotate – sebastien FCT Jul 06 '14 at 02:39
  • Doesn't work, deprecated methods! :( – user3699052 Jul 06 '14 at 02:48

1 Answers1

0

In my case I override the NavigationController and override the following methods:

public myNavController : NavigationController
{
    public override bool ShouldAutorotate ()
    {
        return ShouldAllowLandscape(); // implemet this method to return true only when u want it to
    }

    public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations ()
    {
        var shouldAllowOtherOrientation = ShouldAllowLandscape (); // same here
        if (shouldAllowOtherOrientation) 
        {
            return UIInterfaceOrientationMask.AllButUpsideDown;
        } 

        return UIInterfaceOrientationMask.Portrait;
    }

    bool ShouldAllowLandscape ()
    {
        return TopViewController is xController; // implement this to return true when u want it
    }
}

Please bear in mind this code is in Xamarin.iOS but you could do exactly the same in Obj-C Then u could override the individual methods in ur UIViewControllers to return true or false as you want

Has AlTaiar
  • 4,052
  • 2
  • 36
  • 37