防止 SwiftUI 系统图像动态更改导航栏项目的大小

Prevent SwiftUI System Image from dynamically changing size for navigation bar item

我想在 SwiftUI 中使用系统加号图像向导航栏项目添加加号按钮。但是,当可访问性字体更改时,我无法阻止系统图像动态缩放。

我怎样才能阻止它调整大小,使其像标准的 UINavigationBarButtonItem 系统加按钮一样工作?

对于大字体类型,按住导航栏按钮的辅助功能也不像 UIKit 那样有效。

真的很沮丧,因为 SwiftUI 无法完成一件可能很简单的事情,而且还没有考虑到可访问性。 SwiftUI 教程配置文件栏按钮也不适用于大字体。 (PS SwiftUI 是未来)

这是我的尝试:

struct ContentView : View {
    var body: some View {
        NavigationView {
            List {
                Text("Stop + Bar Button resizing")
                    .lineLimit(nil)
            }
            .navigationBarTitle(Text("Plus"))
            .navigationBarItems(trailing:
                PlusNavigationButton()
            )
        }
    }
}

struct PlusNavigationButton: View {
    var body: some View {
        PresentationButton(
            Image(systemName: "plus")
                .resizable()
                .frame(width: 44, height: 44),
            destination: NewView())
    }
}

您应该构建您真正想要的。所以如果你想使用带有一些额外 hitTest 区域的 16x16 图像,你可以像这样构建:

var body: some View {
    PresentationButton(
        HStack() {
           Spacer()
           Image(systemName: "plus")
               .resizable()
               .frame(width: 16, height: 16)
           Spacer()
        }.frame(width: 44, height: 44),    
        destination: NewView()
    )
}

或者如果您喜欢图像周围的一些 space 并让它填充其余部分,您可以:

var body: some View {
    PresentationButton(
        Image(systemName: "plus")
            .resizable()
            .padding(14)
            .frame(width: 44, height: 44),  
        destination: NewView()
    )
}