我在 ContentView 中有這個結構BarView()
struct ContentView: View {
var body: some View {
NavigationView {
VStack {
BarView()
AdsView()
SelectTypeVideo()
Spacer()
}
.ignoresSafeArea(.all)
}
}
}
它的位置在螢屏的頂部
在一個地方導航標題
我在頂部放了一個按鈕,可以切換到另一個螢屏
我發現的問題是,當我按下螢屏頂部的任何按鈕時,它都沒有回應
例如,當您離開頂部 100 的距離時,按鈕會在您按下時做出回應
是在 ContentView 中使用 NavigationView 的原因
或者問題的原因是什么?
struct BarView: View {
@State var isSearch = false
var body: some View {
HStack {
ZStack {
HStack {
Button(action: { isSearch.toggle() }) {
// All of these buttons do not respond when you press them
ZStack {
Rectangle()
.fill(Color.white)
.cornerRadius(10)
.shadow(color: .black.opacity(0.2), radius: 10)
.frame(maxWidth: 35, maxHeight: 35)
.padding(.top, 25)
Image(systemName: "gear")
.padding(.top, 25).padding()
.foregroundColor(Color.black)
}
}
Button(action: { isSearch.toggle() }) {
// All of these buttons do not respond when you press them
ZStack {
Rectangle()
.fill(Color.white)
.cornerRadius(10)
.shadow(color: .black.opacity(0.2), radius: 10)
.frame(maxWidth: 35, maxHeight: 35)
.padding(.top, 25)
Image(systemName: "magnifyingglass")
.padding(.top, 25).padding()
.foregroundColor(Color.black)
}
}
}
}
Spacer()
Text("Comidia")
.padding(.top, 30).padding()
.font(.title)
}.padding(.top, 10)
.ignoresSafeArea(.all)
.popover(isPresented: $isSearch) {
SearchBar()
}
}
}
uj5u.com熱心網友回復:
由于Spacer()之后SelectTypeVideo(),您的, 位于欄BarView()下方。NavigationView您可以嘗試洗掉該Spacer(),或洗掉NavigationView,或者如果您確實需要NavigationView,請嘗試使用toolbar,例如在這種方法中:
struct ContentView: View {
var body: some View {
NavigationView {
VStack {
Spacer().frame(height: 120) // <-- adjust if need be
AdsView()
SelectTypeVideo()
Spacer()
}
.toolbar { BarView() } // <-- here
.ignoresSafeArea(.all)
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/481981.html
上一篇:在視圖層次結構頂部顯示自定義彈出視圖?SwiftUI
下一篇:collectionView不會在viewDidLoad中重新加載資料,但它可以在viewWillAppear中作業
