gpt4 book ai didi

SwiftUI:使用 anchor 调用 scrollTo 方法时崩溃:.center

转载 作者:行者123 更新时间:2023-12-04 03:52:04 24 4
gpt4 key购买 nike

不能 100% 确定它是否是由 anchor 引起的因为我刚刚删除它并且到目前为止还没有遇到崩溃(如果发生更多崩溃会报告回来) - 有人可以检查并帮助看看这是否真的可能是错误所在吗?还要提交Apple错误。
我的观点是这样的:

var body: some View {
ScrollViewReader { scrollProxy in
ScrollView {
if isShowingContent {
LazyVStack {
ForEach(mo.msgMos.indices, id: \.self) { i in
...
}
}
}
}
.onChange(of: mo.scrollToIdx) { idx in
withAnimation {
scrollProxy.scrollTo(targetIdx, anchor: .center)
}
}
}
}

崩溃堆栈如下所示:
Crashed: com.apple.main-thread
0 AttributeGraph 0x1cedce974 AGGraphGetValue + 284
1 SwiftUI 0x1addcbe5c _ViewCache.layout.getter + 52
2 SwiftUI 0x1addcc2f4 _ViewCache.withPlacementData<A>(_:) + 160
3 SwiftUI 0x1addd02d0 closure #1 in IncrementalScrollable.makeTarget(at:anchor:) + 336
4 SwiftUI 0x1addd6a9c partial apply for closure #1 in IncrementalScrollable.makeTarget(at:anchor:) + 56
5 SwiftUI 0x1ae2241fc HostingScrollView.updateAnimationTarget(_:) + 216
6 SwiftUI 0x1ae2245c4 HostingScrollView.bounds.didset + 188
7 SwiftUI 0x1ae2244e8 HostingScrollView.bounds.setter + 128
8 SwiftUI 0x1ae22444c @objc HostingScrollView.bounds.setter + 44
9 UIKitCore 0x1aa494e4c -[UIScrollView setContentOffset:] + 804
10 UIKitCore 0x1aa48f1e0 -[UIScrollViewScrollAnimation setProgress:] + 320
11 UIKitCore 0x1a95094b8 -[UIAnimator _advanceAnimationsOfType:withTimestamp:] + 276
12 QuartzCore 0x1aa8e46a4 CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 664
13 QuartzCore 0x1aa9bb1a0 display_timer_callback(__CFMachPort*, void*, long, void*) + 280
14 CoreFoundation 0x1a7633ce4 __CFMachPortPerform + 176
15 CoreFoundation 0x1a7658098 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 60
16 CoreFoundation 0x1a7657440 __CFRunLoopDoSource1 + 596
17 CoreFoundation 0x1a7651320 __CFRunLoopRun + 2360
18 CoreFoundation 0x1a76504bc CFRunLoopRunSpecific + 600
19 GraphicsServices 0x1be0d5820 GSEventRunModal + 164
20 UIKitCore 0x1a9ff4734 -[UIApplication _run] + 1072
21 UIKitCore 0x1a9ff9e10 UIApplicationMain + 168
22 Fablur 0x102453f8c main + 12 (AppDelegate.swift:12)
23 libdyld.dylib 0x1a7317e60 start + 4

最佳答案

我发现如果你使用 带 anchor 的 scrollTo 并将 ScrollView 的内容定位到通常无法通过正常滚动到达的位置,然后在删除 View 时它会崩溃。
例如。滚动到 ScrollView 中的最后一个 View 并使用 .leading 或 .center 位置。
我通过在 ScrollView 的末尾添加一个空白 View 来解决这个问题。不理想但有效。

关于SwiftUI:使用 anchor 调用 scrollTo 方法时崩溃:.center,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64309333/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com