0
votes

I have a Universal Xamarin Forms App with a single page wrapped in a NavigationPage:

Current.MainPage = new NavigationPage(new RootPage()
            {
                BackgroundColor = (Color)Application.Current.Resources["BackgroundColour"]
            })
            {
                BackgroundColor = (Color)Application.Current.Resources["BackgroundColour"],
                BarBackgroundColor = (Color)Application.Current.Resources["BackgroundColour"],
                Padding = NavigationPaddingForPlatfrom()
            };

I've also overridden GetSupportedInterfaceOrientations in AppDelegate and set a break point - however the break point is never hit. When I rotate in the simulator or device, the break point isn't hit. I've also set the Device Orientation in info.plist to Portrait only, however the App still rotates.

Am I missing some configuration point that's needed to control orientation?

I'm using Xamarin Forms 2.4.0.38779.

The end goal is to force a MasterDetail Page into landscape only.

3

3 Answers

0
votes

For forcing exact mode this code worked for me:

public MainPage()
    {
        InitializeComponent();
        OnOrientationChanged += OnOrientationChange;
        OnOrientationChange(this, new OrientationChangedEventArgs(DeviceOrientation.Landscape));
    }


private void OnOrientationChange(object sender, OrientationChangedEventArgs e)
    {
        IOrientationService orientationService = DependencyService.Get<IOrientationService>();
        DeviceOrientation currentOrientation = orientationService.GetCurrentOrientation();
        if (currentOrientation != DeviceOrientation.Landscape)
        {
            orientationService.SetCurrentOrientation(DeviceOrientation.Landscape);
        }
    }
0
votes

Have you tried this.

protected override void OnSizeAllocated(double width, double height)
        {
           base.OnSizeAllocated(width, height);
                if (width != this.width || height != this.height)
                {
                    this.width = width;
                    this.height = height;
                    if (Width > Height)
                    {
                       //your grid
                    }
                   else
                    {
                       //your grid
                    }
                }       
         }
0
votes

After reading a lot of article and forum posts, I came across this:

https://forums.xamarin.com/discussion/79389/how-to-lock-orientation-in-landscape-for-an-ipad-only-app

The last post by JoeRaco references this SO post:

Xcode 7 ERROR ITMS-90474: "Invalid Bundle", can't submit to Apple

Without 'Requires full screen' set to true, GetSupportedInterfaceOrientations was not being called in AppDelegate. Therefore adding the following to the info.plist solved my problem:

<key>UIRequiresFullScreen</key>
<true/>