如何解决WatchOS ScrollReader 代理滚动缓慢
对于 WatchOS,我正在尝试构建一个自动滚动到添加到列表的最后一个项目的 ScrollView。这一切都很好,但是一旦 ScrollView 充满了内容,scrollTo
函数就会变得非常缓慢和缓慢。为 withAnimation
设置动画持续时间此时不起作用。任何想法为什么动画开始变慢?提前致谢。
struct ContentView: View {
@State private var items: [Date] = []
static var dateFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "hh:mm:ss:SSS"
return formatter
}()
var body: some View {
VStack {
ScrollView {
ScrollViewReader { scrollProxy in
LazyVStack {
ForEach(items,id: \.self) { item in
Text(Self.dateFormatter.string(from: item))
.font(.system(size: 16.0))
.padding()
.background(
RoundedRectangle(cornerRadius: 8.0)
.fill(Color.blue)
)
.id(item)
}
}
.onReceive(items.publisher) { date in
withAnimation(.easeInOut(duration: 0.25)) {
scrollProxy.scrollTo(date,anchor: .bottom)
}
}
}
}
Button("Add Item",action: { items.append(Date()) })
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。