简体   繁体   English

iOS 15 更新后,iOS 平台中 Xamarin.forms 中的导航栏颜色变化问题

[英]Navigation bar colour change issue in Xamarin.forms in iOS platform after iOS 15 update

In the application I developed, the navigation bar at the bottom of the screen, changes its color between black and white depending on the theme selected by the user.在我开发的应用程序中,屏幕底部的导航栏会根据用户选择的主题在黑色和白色之间改变颜色。 It worked perfectly all this time until I updated the software to iOS 15. Now, even if the user changes it to dark mode, the navigation bar alone stays white (supposed to turn black).在我将软件更新到 iOS 15 之前,它一直运行良好。现在,即使用户将其更改为暗模式,导航栏也会保持白色(应该变成黑色)。 Any idea why this happens?知道为什么会这样吗? This issue only persists in iOS platform.此问题仅在 iOS 平台上存在。

Update 2: Current versions (at the time of writing 5.0.0.2244) should fix this issue更新 2:当前版本(在撰写本文时为 5.0.0.2244)应该可以解决这个问题

Update: Fixes for this are merged and should be released soon!更新:对此的修复已合并,应尽快发布!

This is a known issue that we are tracking here .这是我们在此处跟踪的已知问题。 A workaround is mentioned in there in the form of a custom renderer, I will paste it here but this is specific to Shell though.那里以自定义渲染器的形式提到了一种解决方法,我将其粘贴到此处,但这是特定于 Shell 的。 But it might give you some hint on how to use it on regular components as well.但它也可能会给你一些关于如何在常规组件上使用它的提示。

using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

[assembly: ExportRenderer(typeof(APPNAME.AppShell), typeof(APPNAME.iOS.Renderers.CustomShellRenderer))]
namespace APPNAME.iOS.Renderers
{

    public class CustomShellRenderer : ShellRenderer
    {
        protected override IShellSectionRenderer CreateShellSectionRenderer(ShellSection shellSection)
        {
            var renderer = base.CreateShellSectionRenderer(shellSection);
            
            if (renderer != null)
            {
                if (renderer is ShellSectionRenderer shellRenderer)
                {
                    
    
                    var appearance = new UINavigationBarAppearance();
                    appearance.ConfigureWithOpaqueBackground();
                    appearance.BackgroundColor = new UIColor(red: 0.86f, green: 0.24f, blue: 0.00f, alpha: 1.00f);
                    
                    appearance.TitleTextAttributes = new UIStringAttributes() { ForegroundColor = UIColor.White};
                    
              
                    shellRenderer.NavigationBar.Translucent = false;
                    shellRenderer.NavigationBar.StandardAppearance = appearance;
                    shellRenderer.NavigationBar.ScrollEdgeAppearance = shellRenderer.NavigationBar.StandardAppearance;
                    
                }
            }

            return renderer;
        }

        protected override IShellItemRenderer CreateShellItemRenderer(ShellItem item)
        {
            var renderer = base.CreateShellItemRenderer(item);
            
            if (renderer != null)
            {
                if (renderer is ShellItemRenderer shellItemRenderer)
                {
                    var appearance = new UITabBarAppearance();
                    
                    appearance.ConfigureWithOpaqueBackground();

                    shellItemRenderer.TabBar.Translucent = false;
                    shellItemRenderer.TabBar.StandardAppearance = appearance;
               
                }
                

            }

            return renderer;
        }
        
    }
}

The issue seems to be caused by compiling against Xcode 13/running on iOS 15. Other peoples in the linked issue have mentioned that downgrading their Xcode made it work for them.该问题似乎是由针对 Xcode 13/在 iOS 15 上运行的编译引起的。链接问题中的其他人提到降级他们的 Xcode 使其对他们有用。

TL;DR: we're working on a fix that should be released soon :) TL;DR:我们正在开发一个修复程序,应该很快就会发布:)

Hello the problem is fixed in pre-release Xamarin Form add source Nuget to access it https://aka.ms/forms-prs/index.json您好,问题已在预发布版 Xamarin 表单中修复,添加源 Nuget 以访问它https://aka.ms/forms-prs/index.json

Then you can install the package Xamarin Form 5.0.0.7649 and solve the problem.然后你可以安装包Xamarin Form 5.0.0.7649并解决问题。

To more information visit the bug in the page of proyect in GitHub: https://github.com/xamarin/Xamarin.Forms/issues/14505更多信息请访问 GitHub 项目页面中的错误: https : //github.com/xamarin/Xamarin.Forms/issues/14505

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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