简体   繁体   中英

Hide Home Indicator for iPhone X in Xamarin.Forms page

How to hide the home indicator in a Xamarin.Forms application? Looks like i need to get root UIViewControler of Forms application and somehow override PrefersHomeIndicatorAutoHidden to return true. But i don't have access to that root UIViewControler...

Do you have any ideas how to hide Home Indicator in Xamarin.Forms app?

You should be able to simply create a custom renderer and override this property.

Something like this:

[assembly: ExportRenderer(typeof(MyPage), typeof(HomeIndicatorRenderer))]
namespace MyApp
{ 
    public class HomeIndicatorRenderer : PageRenderer
    {
        public override bool PrefersHomeIndicatorAutoHidden => true;

        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);
            SetNeedsUpdateOfHomeIndicatorAutoHidden();
        }
    }
}

You should probably mix in a check if the version is iOS 11 or higher somewhere.

But as already pointed out, you probably want to be careful with this. And I think the Apple documentation even states that this setting can be ignored by the OS at will.

I use this in the constructor of my Xamarin.Forms.Page after InitializeComponent() :

using Xamarin.Essentials;
using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.iOSSpecific;
// ...

if (Device.RuntimePlatform == Device.iOS &&  
    DeviceInfo.Version.Major > 11)
{
    On<iOS>().SetPrefersHomeIndicatorAutoHidden(true);
}

Based on this source .

My use case was to create clean screenshots in the iOS simulator for the App Store.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM