禁用滚动视图中的过度滚动(SwiftUI)



如何在全屏垂直滚动视图(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
}

最新更新