SafeAreaInsets helped us.
In AppDelegate.CS,
base.FinishedLaunching(uiApplication, launchOptions);
should be replaced with the following code:
var result = base.FinishedLaunching(uiApplication, launchOptions); try { if (UIApplication.SharedApplication.KeyWindow != null) { double top = 0; double bottom = 0; if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0)) { top = UIApplication.SharedApplication.KeyWindow.SafeAreaInsets.Top; bottom = UIApplication.SharedApplication.KeyWindow.SafeAreaInsets.Bottom; } //Store safe area values using NSUserDefaults.StandardUserDefaults DependencyService.Get<ISettingsService>().AddOrUpdateValue("IPhoneXSafeTop", top); DependencyService.Get<ISettingsService>().AddOrUpdateValue("IPhoneXSafeBottom", bottom); DependencyService.Get<ISettingsService>().Save(); } } catch (Exception ex) { Console.WriteLine("Ex in FinishedLaunching: " + ex.Message); } return result;
In PCL, the xaml.cs file adds the code below to the Constructor:
var IPhoneXSafeBottom = DependencyService.Get<ISettingsService> ().GetValueOrDefault<Double> ("IPhoneXSafeBottom", 0); var IPhoneXSafeTop = DependencyService.Get<ISettingsService> ().GetValueOrDefault<Double> ("IPhoneXSafeTop", 0); if (IPhoneXSafeBottom > 0) { MainLayout.Padding = new Thickness(0, IPhoneXSafeTop, 0, IPhoneXSafeBottom); }
source share