Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
特定MvxViewController的mvvmcross ios锁定纵向方向_Ios_Xamarin_Xamarin.ios_Mvvmcross - Fatal编程技术网

特定MvxViewController的mvvmcross ios锁定纵向方向

特定MvxViewController的mvvmcross ios锁定纵向方向,ios,xamarin,xamarin.ios,mvvmcross,Ios,Xamarin,Xamarin.ios,Mvvmcross,我有Xamarin mvvmcross解决方案,支持IOS纵向和横向屏幕方向。IOS 8.0 我想添加新的MvxViewController,但只在纵向模式下锁定它。 我在Internet示例中搜索了ios swift、xamarin表单,但所有这些都不适用于mvvmcross解决方案 有没有办法用Xamarin mvvmcroos锁定一个屏幕的肖像模式 谢谢这与普通的ViewController没有什么不同 public override bool ShouldAutorotate() =&g

我有Xamarin mvvmcross解决方案,支持IOS纵向和横向屏幕方向。IOS 8.0 我想添加新的MvxViewController,但只在纵向模式下锁定它。 我在Internet示例中搜索了ios swift、xamarin表单,但所有这些都不适用于mvvmcross解决方案 有没有办法用Xamarin mvvmcroos锁定一个屏幕的肖像模式


谢谢

这与普通的ViewController没有什么不同

public override bool ShouldAutorotate() => false;
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations() => 
    UIInterfaceOrientationMask.Portrait;

实际上,对我来说,这是一种工作方法: 应用内AppDelegate:MvxApplicationDelegate类i已创建

public bool RestrictRotation = true;
并增加了方法:

[Export("application:supportedInterfaceOrientationsForWindow:")]
public UIInterfaceOrientationMask GetSupportedInterfaceOrientations(UIApplication application, IntPtr forWindow)
{
    if (this.RestrictRotation)
        return UIInterfaceOrientationMask.All;
    else
        return UIInterfaceOrientationMask.Portrait;
} 
然后,对于只需要纵向模式的视图,我使用

public override void ViewWillAppear(bool animated)
{
    base.ViewWillAppear(animated);

    AppDelegate app = (AppDelegate)UIApplication.SharedApplication.Delegate;
    app.RestrictRotation = false;
}
为了支持我设置的所有屏幕旋转:

public override void ViewWillAppear(bool animated)
{
    base.ViewWillAppear(animated);

    AppDelegate app = (AppDelegate)UIApplication.SharedApplication.Delegate;
    app.RestrictRotation = true;
} 
希望这会有帮助!
谢谢你

我需要一个应用程序,除了某些模式视图是横向的以外,其他都是纵向的,所以我在MvvmCross 5.0上为iOS 10这样做:

首先在Info.plist中设置应用程序需要的方向

然后,您需要找到您的
[MvxRootPresentation]
,即您的根视图

根视图将接收来自
ShouldAutorotate
GetSupportedInterfaceOrientations
的调用,然后将这些调用传递给可视控制器(如果它们实现了方法),这两种方法都是虚拟的,因此如果未实现,默认值为ShouldRotate=false GetSupportedInterfaceOrientations=全倒

在根视图中添加
ShouldAutorotate
GetSupportedInterfaceOrientations
方法,如下所示:

public override bool ShouldAutorotate()
{
    return true; // Allows all view to auto rotate if they are wrong orientation
}

public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations()
{
    var orientation = UIInterfaceOrientationMask.Portrait;

    if (VisibleUIViewController != null)
    {
        var VisibleMvxViewController = VisibleUIViewController as MvxViewController;
        if (VisibleMvxViewController != null)
        {
            // Check if the view is a Modal View by checking for the MvxModalPresentationAttribute
            var attribute = VisibleMvxViewController.GetType().GetCustomAttributes(typeof(MvxModalPresentationAttribute), true).FirstOrDefault() as MvxModalPresentationAttribute;
            if (attribute != null)
            {
                // Visible view is a modal
                if (!VisibleUIViewController.IsBeingDismissed)
                {
                    // view is not being dismissed so use the orientation of the modal
                    orientation = VisibleUIViewController.GetSupportedInterfaceOrientations();
                }
            }
        }
    }

    return orientation;
}
然后,在模态视图上(在我的示例中,这些视图具有MvxModalPresentation属性),您要更改方向,请覆盖此方法:

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

此解决方案意味着您无需向AppDelegate添加任何内容

谢谢您的回答,我向控制器添加了代码,但仍不调用ShouldAutorotate。public override bool FinishedLaunching(UIApplication app,NSDictionary options){window=new UIWindow(UIScreen.MainScreen.Bounds);var presenter=new MvxIosViewPresenter(此,窗口);var setup=new setup(此,presenter);setup.Initialize();var startup=Mvx.Resolve();startup.Start();window.MakeKeyAndVisible();return true;}也许我需要更改mvvmcross AppDelegate文件中的某些内容?谢谢,我认为苹果已经改变了iOS 8以后的轮换工作方式。我知道这在iOS 10中是完全不同的。如果您想将方向限制为几个变体,例如UIInterfaceOrientationMask.横向(它包括横向两侧),则应将ShouldAutorotate设置为true。