我希望能夠在滾動視圖上向下拖動,并且大導航標題不能粘在內容上,因為它在向下滾動時隱藏了視圖。
如何禁用此行為?

uj5u.com熱心網友回復:
我能夠修復此行為的方法是向層次結構添加一個假視圖,以便滾動視圖不是螢屏的基本視圖,因為如果滾動視圖是基本視圖,它似乎會自動添加這種粘性行為。只是添加一個普通的VStack或EmptyView似乎不起作用,因為它能夠告訴滾動視圖在某種程度上仍然是基本視圖。
VStack {
// Stops large navigation titles from sticking to the scrollview if the scroll view is the base view
FakeView().fixedSize()
// Your previous root scrollview
ScrollView {
}
}
struct FakeView: UIViewRepresentable {
public func makeUIView(context: UIViewRepresentableContext<Self>) -> UIView {
UIView()
}
public func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext<Self>) {
}
}

uj5u.com熱心網友回復:
它應該在沒有可表示的情況下作業,例如
VStack(spacing: 0) {
Rectangle().fill(.background).frame(height: 1) // iOS 15 !!
// backward-compatible variant
// Color(uiColor: UIColor.systemBackground).frame(height: 1)
// Your previous root scrollview
ScrollView {
}
}
uj5u.com熱心網友回復:
您可以添加一個視圖來填充螢屏,例如 a Color,并將您的應用ScrollView為覆寫
Color.clear.overlay {
ScrollView {
//Content
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/496755.html
