OGeek|极客世界-中国程序员成长平台

标题: ios - 如果使用动画调用 setContentOffset,UIScrollView 会崩溃 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 15:38
标题: ios - 如果使用动画调用 setContentOffset,UIScrollView 会崩溃

我的应用程序创建 UIView 的自定义子类的实例,并将这些实例水平放置在彼此相邻的位置。创建 UIView 类的新实例后,我可以将其添加到 UIScrollView 并重置 contentsize。然后我打电话 [UIScrollView setContentOffsetsome point) animated:NO]. 这工作得很好。 问题是当我用动画调用上述方法时,即 [UIScrollView setContentOffsetsome point) animated:YES] ,应用程序崩溃。 调用堆栈如下所示:

> #0    0x3145b870 in ___forwarding___ ()
> #1    0x313b6650 in _CF_forwarding_prep_0 ()
> #2    0x317d84a2 in -[UIAnimator stopAnimation:] ()
> #3    0x317d84a2 in -[UIAnimator stopAnimation:] ()
> #4    0x317d7f0e in -[UIAnimator(Static) _advance:withTimestamp:] ()
> #5    0x317d7e00 in -[UIAnimator(Static) _LCDHeartbeatCallback:] ()
> #6    0x3531d86e in CA:isplay:isplayLink::dispatch(unsigned long long, unsigned long long) ()
> #7    0x3531d7c4 in CA:isplay::IOMFBDisplayLink::callback(__IOMobileFramebuffer*,
> unsigned long long, unsigned long long, unsigned long long, void*) ()
> #8    0x33a56000 in IOMobileFramebufferVsyncNotifyFunc ()
> #9    0x36e3c60c in IODispatchCalloutFromCFMessage ()
> #10   0x31422f12 in __CFMachPortPerform ()
> #11   0x3142d522 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ ()
> #12   0x3142d4c4 in __CFRunLoopDoSource1 ()
> #13   0x3142c312 in __CFRunLoopRun ()
> #14   0x313af4a4 in CFRunLoopRunSpecific ()
> #15   0x313af36c in CFRunLoopRunInMode ()
> #16   0x32888438 in GSEventRunModal ()
> #17   0x316b4cd4 in UIApplicationMain ()

当我启用 Zombies 时,应用程序输出会产生:

*** -[__NSArrayM removeObject:]: message sent to deallocated instance 0x113dbb10

附加信息:UIScrollView 的委托(delegate)从未设置。我正在使用 ARC。



Best Answer-推荐答案


我发现了我的问题。 我正在从后台线程调用调用 setContentOffset 的方法。

BackgroundThread --> My random processing method --> Setup new UIView and add it to UIScrollView --> Call setContentOffset with animations

上述流程导致崩溃。当我从主线程调用相同的处理方法时,它工作得很好。

显然 iOS 不喜欢从后台线程调用动画。

关于ios - 如果使用动画调用 setContentOffset,UIScrollView 会崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11939016/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4