【问题标题】:Why is the overflow menu empty?为什么溢出菜单是空的?
【发布时间】:2022-11-28 11:01:06
【问题描述】:

在 iPadOS 16.1 中,如果可用空间太小,以下代码将生成一个菜单按钮。虽然无法打开。难道我做错了什么?

NavigationStack {
    VStack {
        Image(systemName: "globe")
            .imageScale(.large)
            .foregroundColor(.accentColor)
        Text("Hello, world!")
    }
    .navigationTitle("Where are the Overflow Menu items?")
    .navigationBarTitleDisplayMode(.inline)
    .toolbarRole(.editor)
    .toolbar {
        ToolbarItemGroup(placement: .secondaryAction) {
            ImageButton(imageName: "person.fill.questionmark")
            ImageButton(imageName: "person.crop.circle.badge.questionmark.fill")
            ImageButton(imageName: "questionmark.app.fill")
            ImageButton(imageName: "questionmark")
            ImageButton(imageName: "questionmark.diamond")
            
            ImageButton(imageName: "person.fill.questionmark")
            ImageButton(imageName: "person.crop.circle.badge.questionmark.fill")
            ImageButton(imageName: "questionmark.app.fill")
            ImageButton(imageName: "questionmark")
            ImageButton(imageName: "questionmark.diamond")
        }
    }
    .padding()
}

这就是它的样子。

编辑我现在在单击菜单按钮时发现了这条日志消息:

[UILog] Called -[UIContextMenuInteraction updateVisibleMenuWithBlock:] while no context menu is visible. This won't do anything.

【问题讨论】:

  • 你能附上问题的图片吗?如果是,请做!
  • 添加了图像并更改了描述。我实际上不确定菜单是否为空,因为如果您设法打开它,那里可能会有项目。

标签: swiftui toolbar ipados


【解决方案1】:

这是正确的实施吗? 当我单击 ToolbarItem 时,我使用“菜单”使其出现。

struct searchNutritionView: View {
    
    
    var body: some View {
        NavigationStack {
            VStack {
                Image(systemName: "globe")
                    .imageScale(.large)
                    .foregroundColor(.accentColor)
                Text("Hello, world!")
            }
            .navigationTitle("Where are the Overflow Menu items?")
            .navigationBarTitleDisplayMode(.inline)
            .toolbarRole(.editor)
            .toolbar {
                ToolbarItemGroup(placement: .navigationBarTrailing) {
                    
                    Menu {
                        ImageButton(imageName: "person.fill.questionmark")
                        ImageButton(imageName: "person.crop.circle.badge.questionmark.fill")
                        ImageButton(imageName: "questionmark.app.fill")
                        ImageButton(imageName: "questionmark")
                        ImageButton(imageName: "questionmark.diamond")
                        
                        ImageButton(imageName: "person.fill.questionmark")
                        ImageButton(imageName: "person.crop.circle.badge.questionmark.fill")
                        ImageButton(imageName: "questionmark.app.fill")
                        ImageButton(imageName: "questionmark")
                        ImageButton(imageName: "questionmark.diamond")
                    } label: {
                        ImageButton(imageName: "ellipsis.circle")
                    }
                }
            }
            .padding()
        }
    }
    
    struct ImageButton: View {
        
        let imageName: String
        
        var body: some View {
            Button {
                print("button pressed")
            } label: {
                Image(systemName: imageName)
                    .renderingMode(.original)
            }
        }
    }
}

struct searchNutritionView_Previews: PreviewProvider {
    static var previews: some View {
        searchNutritionView()
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-25
    • 2013-02-16
    • 2021-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多