微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

更新 contentOffset 时崩溃

如何解决更新 contentOffset 时崩溃

let bottomOffset = bottomView.contentOffset.y
let currentOffset = overlayScrollView?.contentOffset.y ?? CGFloat(0)
let totalOffset = (bottomOffset + currentOffset) > 0 ? (bottomOffset + currentOffset)  : 0
bottomView.contentOffset.y = 0
overlayScrollView?.contentOffset.y = totalOffset

在这条线上的应用程序中遇到了几次 EXC_BAD_ACCESS KERN_PROTECTION_FAILURE 类型的崩溃

overlayScrollView?.contentOffset.y = totalOffset

最初,我认为这是因为 KVO 没有得到正确处理,这可能是消息被发送到释放的对象并且观察者没有被删除。 移动到新的 KVO keyPathBased API,它消除了移除观察者的开销。但是这个问题仍然在发生。就我而言,这个问题根本无法重现。

0  QuartzCore                     0x1a42bb938 CA::Layer::writable_state(CA::Transaction*) + 490
1  QuartzCore                     0x1a42bba74 CA::Layer::end_change(CA::Transaction*,unsigned int,objc_object*,objc_object*) + 32
2  QuartzCore                     0x1a42c4a04 CA::Layer::set_position(CA::Vec2<double> const&,bool) + 312
3  QuartzCore                     0x1a42b2dbc -[CALayer setPosition:] + 48
4  QuartzCore                     0x1a42b3450 -[CALayer setFrame:] + 424
5  UIKitCore                      0x1a3e28df0 -[UIView(Geometry) setFrame:] + 472
6  UIKitCore                      0x1a3dcf4b4 -[UIScrollView _layoutHorizontalScrollIndicatorWithBounds:effectiveInset:contentOffset:fraction:additionalInset:cornerAdjust:showing:recalcSize:verticalIndicatorFrame:] + 1320
7  UIKitCore                      0x1a3dce89c -[UIScrollView _adjustScrollerIndicators:alwaysShowingThem:] + 1288
8  UIKitCore                      0x1a3dbabfc -[UIScrollView setContentOffset:] + 1208
9  UIKitCore                      0x1a3b46ed4 -[UITableView setContentOffset:] + 284
10 Foundation                     0x1a236dbd8 -[NSObject(NSkeyvalueObservingPrivate) _changeValueForKeys:count:maybeOldValuesDict:maybeNewValuesDict:usingBlock:] + 560
11 Foundation                     0x1a22b2600 -[NSObject(NSkeyvalueObservingPrivate) _changeValueForKey:key:key:usingBlock:] + 68
12 Foundation                     0x1a2369614 _NSSetPointValueAndNotify + 300
13 App                            0x10488393c partial apply for closure #2 in PageBaseViewController.updatePanView(view:index:) + 540 (PageBaseViewController.swift:540)
14 App                            0x1048822d8 partial apply for thunk for @escaping @callee_guaranteed (@guaranteed ZScrollView,@in_guaranteed NSkeyvalueObservedChange<CGPoint>) -> () + 4369375960 (<compiler-generated>:4369375960)
15 libswiftFoundation.dylib       0x1a48d6a50 closure #1 in _keyvalueCodingAndobserving.observe<A>(_:options:changeHandler:) + 320
16 libswiftFoundation.dylib       0x1a48d9cc4 specialized NSkeyvalueObservation.Helper._swizzle_me_observeValue(forKeyPath:of:change:context:) + 1268
17 libswiftFoundation.dylib       0x1a48d6494 @objc NSkeyvalueObservation.Helper._swizzle_me_observeValue(forKeyPath:of:change:context:) + 192
18 Foundation                     0x1a236bd70 NSkeyvalueNotifyObserver + 288
19 Foundation                     0x1a236e188 NSkeyvalueDidChange + 324
20 Foundation                     0x1a236dc14 -[NSObject(NSkeyvalueObservingPrivate) _changeValueForKeys:count:maybeOldValuesDict:maybeNewValuesDict:usingBlock:] + 620
21 Foundation                     0x1a22b2600 -[NSObject(NSkeyvalueObservingPrivate) _changeValueForKey:key:key:usingBlock:] + 68
22 Foundation                     0x1a2369614 _NSSetPointValueAndNotify + 300
23 UIKitCore                      0x1a3b386b0 -[UITableView _restoreOrAdjustContentOffsetWithRowCount:initialContentInsetTop:] + 352
24 UIKitCore                      0x1a3b27a50 -[UITableView _updateVisibleCellsNow:] + 3552
25 UIKitCore                      0x1a3b27a78 -[UITableView _updateVisibleCellsNow:] + 3592
26 UIKitCore                      0x1a3b27a78 -[UITableView _updateVisibleCellsNow:] + 3592
27 UIKitCore                      0x1a3b27a78 -[UITableView _updateVisibleCellsNow:] + 3592
28 UIKitCore                      0x1a3b27a78 -[UITableView _updateVisibleCellsNow:] + 3592
29 UIKitCore                      0x1a3b27a78 -[UITableView _updateVisibleCellsNow:] + 3592
30 UIKitCore                      0x1a3b27a78 -[UITableView _updateVisibleCellsNow:] + 3592
31 UIKitCore                      0x1a3b27a78 -[UITableView _updateVisibleCellsNow:] + 3592
32 UIKitCore                      0x1a3b27a78 -[UITableView _updateVisibleCellsNow:] + 3592
33 UIKitCore                      0x1a3b27a78 -[UITableView _updateVisibleCellsNow:] + 3592
34 UIKitCore                      0x1a3b27a78 -[UITableView _updateVisibleCellsNow:] + 3592
35 UIKitCore                      0x1a3b44938 -[UITableView layoutSubviews] + 356
36 UIKitCore                      0x1a3e44910 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2544
37 QuartzCore                     0x1a42b96dc -[CALayer layoutSublayers] + 288
38 QuartzCore                     0x1a42bfe64 CA::Layer::layout_if_needed(CA::Transaction*) + 544
39 QuartzCore                     0x1a42cb424 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 140
40 QuartzCore                     0x1a4213c20 CA::Context::commit_transaction(CA::Transaction*,double,double*) + 500
41 QuartzCore                     0x1a423e970 CA::Transaction::commit() + 668
42 UIKitCore                      0x1a39752c0 _afterCACommitHandler + 140
43 CoreFoundation                 0x1a102d418 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
44 CoreFoundation                 0x1a1027a48 __CFRunLoopDoObservers + 588
45 CoreFoundation                 0x1a1027fe4 __CFRunLoopRun + 1012
46 CoreFoundation                 0x1a10276a8 CFRunLoopRunSpecific + 572
47 GraphicsServices               0x1b76d7570 GSEventRunModal + 160
48 UIKitCore                      0x1a3945370 -[UIApplication _run] + 1052
49 UIKitCore                      0x1a394a8ec UIApplicationMain + 164
50 App                            0x10460b944 main + 15 (main.m:15)
51 libdyld.dylib                  0x1a0d06140 start + 4

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。