ios - 如何防止用户滚动超过某个点?
问题描述
我有一个 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()
}
}
解决方案
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()
}
}
推荐阅读
- reactjs - 将索引传递给父组件函数?
- javascript - import and export function javascript electron
- javascript - 是否可以将值从对象数组列表动态附加到对象中?
- scala - 我需要做些什么来移植 ReactiveMongo scala 以使用猫效果?
- javascript - javascript firestore TypeError:无法读取属性“状态”未定义
- kubernetes - Kubernetes - Ingress: Error: connect ECONNREFUSED 127.0.0.1:80
- data-structures - Struggling terribly on how to start and complete a file
- java - 将ProblemFactChange添加到实时规划的Ssolution后链不一致
- react-native - 在特定屏幕中禁用后退按钮(反应导航堆栈)
- javascript - 删除 Ticker Widget 上的 Tradingview 徽标