Xamarin and ios 10 - All Pages moved up behind Tit

2019-04-15 23:46发布

问题:

I have recently updated to ios 10 and all of my Xamarin pages and have been bumped up behind the title bar. Also the bottom of the page now does not touch the screen, it has also been bumped up.

This has happened not just for local projects, but also for an App I have already published in the App store!

The pages are bumped up around 200px or the height of the title bar.

Does anyone know of anything I can do for this???!?

回答1:

To fix this issue, update to the latest version of the Xamarin Forms Nuget Package. To do this right click on your solution in Xamarin Studio and click Update Nuget Packages. This will update all of your NuGet Packages including the Xamarin.Forms nuget package, and will fix this issue.

Note that just installing the latest version of Xamarin Studio will not fix this, you must manually update the Nuget Packages!

Credit goes to @Scott for his help!!!



回答2:

I had the same issue in my Xamarin.Forms app. What I had to do was set the NavigationBar translucent property to false through a custom renderer. If you're not using Forms, you can set this value in the ViewController itself.

        var navBar = this.NavigationController?.NavigationBar;
        if (navBar != null)
        {
            navBar.Translucent = false;
        }

Again, if you're not using forms, try setting the navigation bar's translucent property to false in the ViewController, or Storyboard.

I will say though, that for Forms, this was only required on older versions of Xamarin.Forms, and the latest version fixes this itself.

Edit: Quick (untested) Content Page renderer that should resolve this issue

using TestApp.iOS;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

[assembly:ExportRenderer(typeof(ContentPage), typeof(ContentPageRenderer))]
namespace TestApp.iOS
{
    public class ContentPageRenderer : PageRenderer
    {
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);

            var navBar = this.NavigationController?.NavigationBar;
            if (navBar != null)
            {
                navBar.Translucent = false;
            }
        }
    }
}