Xamarin形式的iPhone X的额外底部和顶部空间 [英] Extra bottom and top space in iPhone X in Xamarin form
问题描述
我正在使用XAML进行UI设计,我的应用程序在不到Iphone X的设备上运行良好.只有Iphone X的问题是顶部和底部的多余空间.
如果我对Iphone X Safe区域启用使用以下代码,则底部和顶部将获得更多空间.在< Xamarin.Forms.PlatformConfiguration.iOS>().SetUseSafeArea(true);
我在这里获得了SafeArea布局设置代码
我在Xamarin形式的Iphone X的代码或设置中缺少的内容
我已经解决了这个问题.
这是一个答案.
-
PCL创建一个要在IOS Native App中使用的接口.
公共接口IDeviceInfo{bool IsIphoneXDevice();}
-
在IOS Native App中实现此接口.
[程序集:依赖项(typeof(DeviceInfoService))]命名空间POC.iOS.DependencyServices{公共类DeviceInfoService:IDeviceInfo{公共DeviceInfoService(){}公共布尔IsIphoneXDevice(){如果(UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone){如果((UIScreen.MainScreen.Bounds.Height * UIScreen.MainScreen.Scale)== 2436){返回true;}}返回false;}}}
-
使用依赖项服务以Xamarin形式调用此方法,并为iPhone X布局编写逻辑.
公共局部类Page:ContentPage{公开页面(){InitializeComponent();var isDeviceIphone = DependencyService.Get< IDeviceInfo>().IsIphoneXDevice();如果(isDeviceIphone){var safeInsets = On< Xamarin.Forms.PlatformConfiguration.iOS>().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 a Answer.
PCL create a interface to consume in IOS Native App.
public interface IDeviceInfo { bool IsIphoneXDevice(); }
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; } } }
Call this method in Xamarin form using dependency Service.And write logic for 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屋!