【发布时间】:2021-09-23 11:59:10
【问题描述】:
我在 iOS 15 中遇到了ScrollView 的问题。
使用scrollTo时,项目垂直弹跳。
我在 iOS 14 中没有这个问题。弹跳是非常随机的,根本没有逻辑来试图了解它何时会跳动。
如果我从滚动视图中删除填充,它是固定的,但我需要 UI 设计师要求的额外空间。
另外,尝试使用.frame 而不是.padding 并且结果相同。
有谁知道如何解决这个问题,或者为什么它只发生在 iOS 15 中?
代码:
ScrollView(.horizontal, showsIndicators: false) {
ScrollViewReader{ proxy in
HStack(spacing: 32){
ForEach(...){ index in
QuestionCell(...)
.scaleEffect(selectedIndex == index ? 1.175 : 1.0)
.onTapGesture{
withAnimation(.spring()){
selectedIndex = index
}
}
}
}
.padding(.leading)
.padding() // Removing this fixes the bounce bug.
.onChange(of: selectedIndex) { value in
withAnimation(.spring()){
let paramsCount = <SOME MODEL>.count
if value < paramsCount{
proxy.scrollTo(value, anchor: .center)
}else{
proxy.scrollTo(paramsCount - 1, anchor: .center)
}
}
}
}
}
}
【问题讨论】:
标签: ios swift animation swiftui scrollview