gpt4 book ai didi

c# - Xamarin 形式的 iPhone X 中额外的底部和顶部空间

转载 作者:太空狗 更新时间:2023-10-29 20:15:45 25 4
gpt4 key购买 nike

我正在使用 XAML 进行 UI 设计,我的应用程序在低于 Iphone X 的设备上运行良好。Iphone X 中唯一的问题是顶部和底部都有额外的空间。

如果我使用以下代码启用 Iphone X 安全区域,它会在底部和顶部获得更多空间。 On<Xamarin.Forms.PlatformConfiguration.iOS>().SetUseSafeArea(true);

我在这里得到了 SafeArea 布局设置代码 SetUserSafeArea

我还使用 SetHasNavigationBar 来禁用标题导航标题。但是在 Iphone X 中没有运气。

NavigationPage.SetHasNavigationBar(this, false);

这是 Iphone X 中的实际输出 enter image description here

我在 Xamarin Form 的 Iphone X 代码或设置中缺少什么

最佳答案

我已经解决了这个问题。

这是一个答案。

  1. PCL 创建一个接口(interface)以在 IOS Native App 中使用。

     public interface IDeviceInfo
    {
    bool IsIphoneXDevice();
    }
  2. 在 IOS Native App 中实现此接口(interface)。

     [assembly: Dependency(typeof(DeviceInfoService))]
    namespace POC.iOS.DependencyServices
    {
    public class DeviceInfoService:IDeviceInfo
    {
    public DeviceInfoService() { }

    public bool IsIphoneXDevice()
    {
    if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone)
    {
    if ((UIScreen.MainScreen.Bounds.Height * UIScreen.MainScreen.Scale) == 2436)
    {
    return true;
    }
    }
    return false;
    }
    }
    }
  3. 使用依赖服务以 Xamarin 形式调用此方法。并编写 iPhone X 布局的逻辑。

     public partial class Page : ContentPage
    {
    public Page()
    {
    InitializeComponent();

    var isDeviceIphone = DependencyService.Get<IDeviceInfo>().IsIphoneXDevice();
    if (isDeviceIphone)
    {
    var safeInsets = On<Xamarin.Forms.PlatformConfiguration.iOS>().SafeAreaInsets();
    safeInsets.Bottom =20;
    safeInsets.Top = 20;
    this.Padding = safeInsets;
    }
    }
    }

关于c# - Xamarin 形式的 iPhone X 中额外的底部和顶部空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49166915/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com