开发者社区> 问答> 正文

如何使navigationBarTitle和navigationBarItem的重叠区域可点击

目前只有红色区域的中部是可触的,我知道下面的区域与导航BarTitle重叠,但我仍然不知道是否可以使下面的区域也是可触的。https://i.stack.imgur.com/ytDvl.gif

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() )
    }
}

展开
收起
游客5akardh5cojhg 2019-12-10 22:46:17 487 0
1 条回答
写回答
取消 提交回答
  • 代码中的两个小改动

    .navigationBarItems(
                leading: EditButton(),
                trailing:
                Button(
                    action: { self.modalIsPresented = true }
                ) {
                    Image(systemName: "plus")
                    .padding()
                    .background(Color.red)
                }
            )
    
    2019-12-10 22:46:38
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载