Xamarin 形式的 iPhone X 中的额外底部和顶部空间 [英] Extra bottom and top space in iPhone X in Xamarin form

查看:26
本文介绍了Xamarin 形式的 iPhone X 中的额外底部和顶部空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 XAML 进行 UI 设计,我的应用在不到 Iphone X 的设备上运行良好.Iphone X 的唯一问题是顶部和底部有额外空间.

如果我使用下面的代码启用 Iphone X 安全区域,它会在底部和顶部获得更多空间.On().SetUseSafeArea(true);

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

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

解决方案

我已经解决了这个问题.

这是一个答案.

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

     公共接口 IDeviceInfo{bool IsIphoneXDevice();}

  2. 在 IOS Native App 中实现这个接口.

     [程序集:依赖(typeof(DeviceInfoService))]命名空间 POC.iOS.DependencyServices{公共类 DeviceInfoService:IDeviceInfo{公共设备信息服务(){}public bool IsIphoneXDevice(){if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone){如果((UIScreen.MainScreen.Bounds.Height * UIScreen.MainScreen.Scale)== 2436){返回真;}}返回假;}}}

  3. 使用依赖服务以 Xamarin 形式调用此方法.并编写 iPhone X 布局的逻辑.

     公共部分类 Page : ContentPage{公共页面(){初始化组件();var isDeviceIphone = DependencyService.Get().IsIphoneXDevice();如果(isDeviceIphone){var safeInsets = On().SafeAreaInsets();safeInsets.Bottom =20;safeInsets.Top = 20;this.Padding = safeInsets;}}}

I'm using XAML for UI design my app is working fine in less then Iphone X device.Only problem in Iphone X it's getting top and bottom Extra space.

If I use below code for Iphone X Safe area enable, it's getting more space in bottom and top. On<Xamarin.Forms.PlatformConfiguration.iOS>().SetUseSafeArea(true);

I got SafeArea layout setting code here SetUserSafeArea

Also i'm using SetHasNavigationBar for disable header navigation title.But there is no luck in Iphone X.

NavigationPage.SetHasNavigationBar(this, false);

Here is actual Output in Iphone X

What i 'm missing in code or setting for Iphone X in Xamarin Form

解决方案

I have solved this issue.

Here is an answer.

  1. PCL create an interface to consume in IOS Native App.

     public interface IDeviceInfo
     {
         bool IsIphoneXDevice();
     }
    

  2. Implement this Interface in IOS Native App.

     [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. Call this method in Xamarin form using dependency Service. And write the logic for the iPhone X layout.

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

这篇关于Xamarin 形式的 iPhone X 中的额外底部和顶部空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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