简体   繁体   中英

Xamarin iOS 10 landscape

My goal is to force landscape orientation on a single view controller , not the entire app (to be exact: I want to make my camera view controller to be landscape only)

I've been running into the issue not being able to force landscape on iOS 10 devices with Xamarin.iOS.

I've got it working on iOS 9 or lower by overriding the following methods in the view controller that is supposed to be in landscape only. However, these methods don't seem to be called on iOS 10.

public override bool ShouldAutorotate()
{
    return true;
}
public override UIInterfaceOrientation PreferredInterfaceOrientationForPresentation()
{
    return UIInterfaceOrientation.LandscapeLeft;
}
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations()
{
    return UIInterfaceOrientationMask.Landscape;
}

I also tested calling this method from ViewDidLoad (I'm not using this line anymore and can't tell if it has any effect)

//AppDelegate
public void ChangeOri()
    {
        UIDevice.CurrentDevice.SetValueForKey(new NSNumber((int)UIInterfaceOrientation.LandscapeLeft), new NSString("orientation"));
    }

Any suggestions on a possible workaround?

I finally found an answer, it has nothing to do with iOS 10 itself.

I had the issue on iPad devices. iPads with iOS9 or higher have received a new function: "Multitasking". Refer to this thread to learn more about.

The crux is, when your app is set to be multitasking you can no longer change orientations from code. You have to enable fullscreen mode for the whole app to make the lines of code be called that I posted in my question above.

Set in your plist: UIRequiresFullScreen to true to do so.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM