在 ScrollView (SwiftUI) 中禁用过度滚动
Disable overscroll in ScrollView (SwiftUI)
如何在全屏垂直 ScrollView (SwiftUI) 中禁用过度滚动?
https://www.youtube.com/watch?v=dOyWCDhlxv8 - 过度滚动的示例(我知道,在视频旧 Android 设备上)
var body: some View {
GeometryReader { geometry in
ScrollView([.vertical], showsIndicators: false)
{
VStack
{
VStack (alignment: .leading) {
ForEach (0..<leftmenuuser.menuitems.count)
{ i in
if (leftmenuuser.menuitems[i].index >= 0)
{
HStack {
HStack (spacing: leftmenuuser.self.iconssize)
{
Image(leftmenuuser.menuitems[i].imagename).resizable().frame(width: leftmenuuser.self.iconssize, height: leftmenuuser.self.iconssize)
Text(leftmenuuser.menuitems[i].title).foregroundColor(Color.white).font(.custom("PFDinTextCompPro-Regular", size: leftmenuuser.self.smallfontsize)).lineLimit(1)
Spacer()
}.padding(leftmenuuser.self.mypadding).frame(maxWidth: .infinity)
}.background(self.selectedindex == leftmenuuser.menuitems[i].index ? Color.yellow : Color.white).onTapGesture {
leftmenuuser.menuitems[i].action(leftmenuuser.menuitems[i])
self.selectedindex = leftmenuuser.menuitems[i].index
self.showmenu = false
}
}
}
}
Spacer()
}
.background(Color.blue).frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
}.background(Color.red).edgesIgnoringSafeArea(.all)
}
}
您可以关闭该特定视图的弹跳:
var body: some View {
init() {
UIScrollView.appearance().bounces = false
}
GeometryReader { geometry in
ScrollView([.vertical], showsIndicators: false)
{
VStack
{
VStack (alignment: .leading) {
ForEach (0..<leftmenuuser.menuitems.count)
{ i in
if (leftmenuuser.menuitems[i].index >= 0)
{
HStack {
HStack (spacing: leftmenuuser.self.iconssize)
{
Image(leftmenuuser.menuitems[i].imagename).resizable().frame(width: leftmenuuser.self.iconssize, height: leftmenuuser.self.iconssize)
Text(leftmenuuser.menuitems[i].title).foregroundColor(Color.white).font(.custom("PFDinTextCompPro-Regular", size: leftmenuuser.self.smallfontsize)).lineLimit(1)
Spacer()
}.padding(leftmenuuser.self.mypadding).frame(maxWidth: .infinity)
}.background(self.selectedindex == leftmenuuser.menuitems[i].index ? Color.yellow : Color.white).onTapGesture {
leftmenuuser.menuitems[i].action(leftmenuuser.menuitems[i])
self.selectedindex = leftmenuuser.menuitems[i].index
self.showmenu = false
}
}
}
}
Spacer()
}
.background(Color.blue).frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
}.background(Color.red).edgesIgnoringSafeArea(.all)
}
}
或者通过将此添加到您的 AppDelegate 来针对整个应用中的所有滚动视图:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
UIScrollView.appearance().bounces = false
}
如何在全屏垂直 ScrollView (SwiftUI) 中禁用过度滚动?
https://www.youtube.com/watch?v=dOyWCDhlxv8 - 过度滚动的示例(我知道,在视频旧 Android 设备上)
var body: some View {
GeometryReader { geometry in
ScrollView([.vertical], showsIndicators: false)
{
VStack
{
VStack (alignment: .leading) {
ForEach (0..<leftmenuuser.menuitems.count)
{ i in
if (leftmenuuser.menuitems[i].index >= 0)
{
HStack {
HStack (spacing: leftmenuuser.self.iconssize)
{
Image(leftmenuuser.menuitems[i].imagename).resizable().frame(width: leftmenuuser.self.iconssize, height: leftmenuuser.self.iconssize)
Text(leftmenuuser.menuitems[i].title).foregroundColor(Color.white).font(.custom("PFDinTextCompPro-Regular", size: leftmenuuser.self.smallfontsize)).lineLimit(1)
Spacer()
}.padding(leftmenuuser.self.mypadding).frame(maxWidth: .infinity)
}.background(self.selectedindex == leftmenuuser.menuitems[i].index ? Color.yellow : Color.white).onTapGesture {
leftmenuuser.menuitems[i].action(leftmenuuser.menuitems[i])
self.selectedindex = leftmenuuser.menuitems[i].index
self.showmenu = false
}
}
}
}
Spacer()
}
.background(Color.blue).frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
}.background(Color.red).edgesIgnoringSafeArea(.all)
}
}
您可以关闭该特定视图的弹跳:
var body: some View {
init() {
UIScrollView.appearance().bounces = false
}
GeometryReader { geometry in
ScrollView([.vertical], showsIndicators: false)
{
VStack
{
VStack (alignment: .leading) {
ForEach (0..<leftmenuuser.menuitems.count)
{ i in
if (leftmenuuser.menuitems[i].index >= 0)
{
HStack {
HStack (spacing: leftmenuuser.self.iconssize)
{
Image(leftmenuuser.menuitems[i].imagename).resizable().frame(width: leftmenuuser.self.iconssize, height: leftmenuuser.self.iconssize)
Text(leftmenuuser.menuitems[i].title).foregroundColor(Color.white).font(.custom("PFDinTextCompPro-Regular", size: leftmenuuser.self.smallfontsize)).lineLimit(1)
Spacer()
}.padding(leftmenuuser.self.mypadding).frame(maxWidth: .infinity)
}.background(self.selectedindex == leftmenuuser.menuitems[i].index ? Color.yellow : Color.white).onTapGesture {
leftmenuuser.menuitems[i].action(leftmenuuser.menuitems[i])
self.selectedindex = leftmenuuser.menuitems[i].index
self.showmenu = false
}
}
}
}
Spacer()
}
.background(Color.blue).frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
}.background(Color.red).edgesIgnoringSafeArea(.all)
}
}
或者通过将此添加到您的 AppDelegate 来针对整个应用中的所有滚动视图:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
UIScrollView.appearance().bounces = false
}