MvvmCross:如何在iPhone上的iOS 7中强制MvxViewController上的特定方向

时间:2013-10-23 23:13:56

标签: ios iphone xamarin.ios mvvmcross

在我的iOS 7应用程序中,我只允许“支持的设备方向”上的“纵向”用于整个应用程序,除了我需要在“视频播放器”视图中允许“横向”方向。我怎么能用MvvmCross或MvxViewController做到这一点? 我试图设置那些ShouldAutorotate(),GetSupportedInterfaceOrientations()方法,它什么也没做。它在“视频播放器”视图中保持锁定在纵向模式。有谁知道在视图上设置方向的正确方法是什么?

 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);
    }    

}

更新:我想出了如何解决这个问题。

步骤1)对于mvvmcross,你必须设置一个新的ViewPresenter,继承自MvxModalNavSupportTouchViewPresenter

步骤2)创建一个继承自UINavigationController的新导航控制器 使用以下代码

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

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

步骤3)在刚刚在步骤1中创建的新View Presenter中,覆盖CreateNavigationController方法并使用您在步骤2中创建的新NavigationController。

步骤4)在ViewController上,您想要更改方向,可以通过重写GetSupportedInterfaceOrientations方法来更改方向。例如,在我的VideoPlayerView上,我在下面有这些代码。

    public override bool ShouldAutorotate()
    {
        return true;
    }

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

0 个答案:

没有答案