MvvmCross: How to force a specific orientation on MvxViewController in iOS 7 on iPhone

Deadly 提交于 2019-12-19 10:07:29

问题


On my iOS 7 app, I only allow "Portrait" on "Supported Device Orientation" for entire application except I need to allow "Landscape" orientation on a "Video player" view. How can I do it with MvvmCross or MvxViewController? I have tried to set those ShouldAutorotate(), GetSupportedInterfaceOrientations() methods, it doesn't do anything. It keeps locked on Portrait mode for "Video player" view. Do anyone know what is the right way to set orientation on a View?

 public class VideoPlayerView : MvxViewController
 {
    public override bool ShouldAutorotate()
    {
        return true;
    }

    public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations()
    {
        return UIInterfaceOrientationMask.AllButUpsideDown;
    }

    public override UIInterfaceOrientation PreferredInterfaceOrientationForPresentation()
    {
        return UIInterfaceOrientation.LandscapeLeft;
    }

    public override void ViewDidLoad(bool animated)
    {
        Title = "Video";

        base.ViewDidLoad(animated);
    }    

}

UPDATE: I figured out how to fix this problem.

Step 1) For mvvmcross, you have to set up a new ViewPresenter with inherit from MvxModalNavSupportTouchViewPresenter

Step 2) Create a new Navigation controller inherit from UINavigationController with the following code

            public override bool ShouldAutorotate()
            {
                return TopViewController.ShouldAutorotate();
            }

            public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations()
            {
                var orientation = TopViewController.GetSupportedInterfaceOrientations();
                return orientation;
            }

Step 3) Inside the new View Presenter you just created on Step 1, override CreateNavigationController method and use the new NavigationController you created on Step 2.

Step 4) On the ViewController you want to change the orientation, you can change it by overriding GetSupportedInterfaceOrientations method. For example, on my VideoPlayerView, I have these code below.

    public override bool ShouldAutorotate()
    {
        return true;
    }

    public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations()
    {
        return UIInterfaceOrientationMask.AllButUpsideDown;
    }

来源:https://stackoverflow.com/questions/19554036/mvvmcross-how-to-force-a-specific-orientation-on-mvxviewcontroller-in-ios-7-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!