我有一個 ScrollView,當我向上滾動時,螢屏上的內容會向下移動。但我想限制內容可以向下移動的程度。我不希望用戶能夠滾動到頂部的灰色矩形之外。換句話說,我不希望用戶在向上滾動時看到灰色矩形上方的白色區域。我怎樣才能在 SwiftUI 中實作這一點?

import SwiftUI
struct ScrollViewIssue: View {
var body: some View {
ScrollView {
VStack {
Rectangle()
.foregroundColor(.gray)
.frame(height: 200)
Circle()
.frame(width: 300, height: 300)
Circle()
.frame(width: 300, height: 300)
Circle()
.frame(width: 300, height: 300)
Circle()
.frame(width: 300, height: 300)
}
}.ignoresSafeArea()
}
}
uj5u.com熱心網友回復:
struct ScrollViewIssue: View {
var body: some View {
ScrollView {
VStack {
Rectangle()
.foregroundColor(.gray)
.frame(height: UIScreen.main.bounds.height)
.frame(height: 200, alignment: .bottom)
Circle()
.frame(width: 300, height: 300)
Circle()
.frame(width: 300, height: 300)
Circle()
.frame(width: 300, height: 300)
Circle()
.frame(width: 300, height: 300)
}
}.ignoresSafeArea()
}
}
uj5u.com熱心網友回復:
您可以從滾動視圖中洗掉“彈跳”效果,例如
UIScrollView.appearance().bounces = false
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/322502.html
