【问题标题】:How to make the overlap area of navigationBarTitle and navigationBarItem tappable - SwiftUI如何使navigationBarTitle和navigationBarItem的重叠区域可点击 - SwiftUI
【发布时间】:2019-12-10 12:43:49
【问题描述】:

目前只有红色区域的中间部分是可点击的,我知道下面的区域与navigationBarTitle重叠,但我仍然想知道是否可以让下面的区域也可以点击。

import SwiftUI

struct ContentView: View {
    @ObservedObject var taskStore: TaskStore
    @State var modalIsPresented = false

    var body: some View {
        NavigationView {
            List {
                ForEach(taskStore.tasks) { index in
                    RowView(task: self.$taskStore.tasks[index])
                }
                .onMove { sourceIndices, destinationIndex in
                    self.taskStore.tasks.move(
                        fromOffsets: sourceIndices,
                        toOffset: destinationIndex
                    )
                }
                .onDelete { indexSet in
                    self.taskStore.tasks.remove(atOffsets: indexSet)
                }
            }
            .navigationBarTitle("Tasks")
            .navigationBarItems(
                leading: EditButton(),
                trailing:
                Button(
                    action: { self.modalIsPresented = true }
                ) {
                    Image(systemName: "plus")
                    .padding(EdgeInsets(top: 50, leading: 50, bottom: 50, trailing: 10))
                    .background(Color.red)
                }
            )
            }
        .sheet(isPresented: $modalIsPresented) {
            NewTaskView(taskStore: self.taskStore)
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView( taskStore: TaskStore() )
    }
}

【问题讨论】:

    标签: ios swift iphone xcode swiftui


    【解决方案1】:

    你的代码有两个小改动

    .navigationBarItems(
                leading: EditButton(),
                trailing:
                Button(
                    action: { self.modalIsPresented = true }
                ) {
                    Image(systemName: "plus")
                    .padding()
                    .background(Color.red)
                }
            )
    

    【讨论】:

    • 感谢您的回答。而我的意思是让那个已经延伸到 barTitle 范围的区域。我刚刚添加了该地区的照片,但看起来不可行。
    猜你喜欢
    • 1970-01-01
    • 2022-01-16
    • 1970-01-01
    • 2021-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多