我尝试增加NavigationView内按钮的可触摸区域,即使区域变大也不起作用。我的代码如下:
var body: some View {
NavigationView {
List(taskStore.tasks) { tasks in
Text(tasks.name)
}
.navigationBarTitle("Tasks")
.navigationBarItems(
trailing: Button(action: {
self.modalIsPresented = true
}){
Image(systemName: "plus")
.frame(width: 200, height: 200)
.contentShape(Rectangle())
.background(Color.yellow)
})}
翻译结果:
绿色区域可触摸,红色区域不可触摸。
我在网上找到了一个解决方案。但是这个解决方案只适用于不在NavigationView中的按钮。因此,如果我将按钮放在“某个视图”中,如下所示,则可以按照解决方案正常工作:
var body: some View {
Button(action: {self.modalIsPresented = true} ) {
Text("Default padding")
.padding(50)
.background(Color.yellow)
}}}
但是当我把按钮放在像我的代码中的导航视图中时,黄色区域是不可触摸的。如何使整个黄色区域(红框)可以像解决方案一样被触摸?谢谢:D
解决方案示例:
![enter image description here](https://istack.dev59.com/vrDJd.webp)