Xamarin iOS 防止特定视图控制器的旋转 [英] Xamarin iOS Prevent rotation for specific viewcontroller

查看:48
本文介绍了Xamarin iOS 防止特定视图控制器的旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要防止特定视图控制器上的屏幕旋转
我试过以下 -

Need to prevent screen rotation on specific view controller
I've tried below-

    public override bool ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientation toInterfaceOrientation)
    {
        return false;
    }


    public override bool ShouldAutorotate()
    {
        return false;
    }


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


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


没有任何效果.


Nothing worked.

提前致谢!

推荐答案

你可以通过这个解释解决这个问题.

You can solve this problem with this explanation.

1) 在你的 AppDelegate 中添加一个布尔值,例如

1) In you AppDelegate add a boolean for example

public bool disableAllOrientation = false;

2) 在 AppDelegate 中修改你的 UIInterfaceOrientationnMask

2) Modify your UIInterfaceOrientationnMask in the AppDelegate

  public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations(UIApplication application, UIWindow forWindow)
        {
            if (disableAllOrientation == true)
            {
              return UIInterfaceOrientationMask.Portrait;
            }
            return UIInterfaceOrientationMask.All;
        }

3) 调用你想要改变方向的视图的控制器

3) Call in the controller of the view that you want change orientation

appDelegate.disableAllOrientation = true;

4) 当视图关闭或更改时,您需要再次放置布尔值错误并仅在需要时将屏幕置于原始方向.

4) and when the view is close or change you need to put again the boolean in false and put your screen in the original orientation only if you want.

appDelegate.disableAllOrientation = false;

我希望这能解决您的问题 我几天前也遇到了同样的问题,这对我有帮助.

I hope this solve your problem I have the same problem days ago and this help me.

这篇关于Xamarin iOS 防止特定视图控制器的旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆