【问题标题】:Xamarin orientation info.plistXamarin 方向信息.plist
【发布时间】:2019-06-28 18:25:10
【问题描述】:

我在 ISO 设置设备方向时遇到问题。对于 iPhone,我想将其锁定为仅纵向模式,但对于 iPad,我希望用户能够使用纵向、左右横向。该设置不会为每个设备保存。

我需要以不同的方式执行此操作吗?

【问题讨论】:

    标签: xamarin.forms xamarin.ios


    【解决方案1】:

    使用文本编辑器打开您的 info.plist。应该有两个方向部分,您可以在其中定义每个成语的方向,如下所示

    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    

    如果这不能正常工作,您也可以在代码中解决这个问题。在 AppDelegate.cs 中尝试覆盖 GetSupportedInterfaceOrientations。

    public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations
    (
      UIApplication application, 
      [Transient] UIWindow forWindow
    )
    {
      // You will need to figure out how to determine what kind of device you're on. I suggest Xamarin.Essentials, they probably have a service for that.
      if (iPhone)
      {
        return UIInterfaceOrientationMask.Portrait;
      }
    
      if (iPad)
      {
        return UIInterfaceOrientationMask.AllButUpsideDown;
      }
    
      return UIInterfaceOrientationMask.All;
    }
    

    【讨论】:

    • 对于 iPhone,当我向左移动时,它很好地保持纵向,但向右时它进入横向
    • @Jefferson 添加了一种以编程方式解决此问题的方法。
    猜你喜欢
    • 2011-02-20
    • 1970-01-01
    • 1970-01-01
    • 2018-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-06
    相关资源
    最近更新 更多