来自 UIImageView 的难以捉摸的硬崩溃 'unrecognized selector sent to instance'

Elusive hard crash from UIImageView 'unrecognized selector sent to instance'

仅在将 2+ 张新照片保存到 phone/simulator 的相机胶卷(在应用程序之外 - camera/save 图像到相机胶卷)。

最奇怪的是,实际访问相机胶卷的代码直到该故事板的未来视图才执行(所以这不是问题所在)。

我已将其缩小为来自之前已加载到主屏幕上的某些 UIImageView,但令人费解的是为什么只有当相机胶卷获取新照片时才会发生这种情况。

-[__NSCFType animationForKey:]: unrecognized selector sent to instance 0x600000827a00

>     0   CoreFoundation                      0x000000010ad9dd4b __exceptionPreprocess + 171
>     1   libobjc.A.dylib                     0x000000010a80621e objc_exception_throw + 48
>     2   CoreFoundation                      0x000000010ae0df04 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
>     3   CoreFoundation                      0x000000010ad23005 ___forwarding___ + 1013
>     4   CoreFoundation                      0x000000010ad22b88 _CF_forwarding_prep_0 + 120
>     5   UIKit                               0x0000000108a9dc11 -[UIImageView isAnimating] + 156
>     6   UIKit                               0x0000000108a9db25 -[UIImageView stopAnimating] + 116
>     7   UIKit                               0x0000000108a9b46b -[UIImageView dealloc] + 51
>     8   CoreFoundation                      0x000000010adf525e common_removeAllObjects + 254
>     9   CoreFoundation                      0x000000010acd1c93 -[__NSArrayM dealloc] + 19
>     10  libobjc.A.dylib                     0x000000010a81ab12 _ZN11objc_object17sidetable_releaseEb + 212
>     11  libobjc.A.dylib                     0x000000010a81b1d1 _ZN12_GLOBAL__N_119AutoreleasePoolPage3popEPv + 715
>     12  QuartzCore                          0x00000001083b7371 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 369
>     13  QuartzCore                          0x00000001083e43ff _ZN2CA11Transaction6commitEv + 475
>     14  UIKit                               0x0000000108883d9b _UIApplicationFlushRunLoopCATransactionIfTooLate + 206
>     15  UIKit                               0x000000010908e77c __handleEventQueue + 5672
>     16  CoreFoundation                      0x000000010ad42761 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
>     17  CoreFoundation                      0x000000010ad2798c __CFRunLoopDoSources0 + 556
>     18  CoreFoundation                      0x000000010ad26e76 __CFRunLoopRun + 918
>     19  CoreFoundation                      0x000000010ad26884 CFRunLoopRunSpecific + 420
>     20  GraphicsServices                    0x000000010d07ea6f GSEventRunModal + 161
>     21  UIKit                               0x000000010888ac68 UIApplicationMain + 159
>     22  MyApp                               0x0000000104f652b2 main + 114
>     23  libdyld.dylib                       0x000000010bbd568d start + 1
>     24  ???                                 0x0000000000000001 0x0 + 1

在逐步注释掉可能导致此崩溃的代码之后,我将其缩小到以下代码,这些代码在实例化的情节提要中隐藏了状态栏

override func prefersStatusBarHidden() -> Bool {
    return true
}

我的猜测是状态栏的隐藏会强制主屏幕视图重新布局,这会导致 UIImageView 之一出现异常。所以,我决定暂时停止隐藏状态栏,因为它对应用程序来说不是必需的。希望这有助于看到相同异常的人。

override func prefersStatusBarHidden() -> Bool {
     return **false**
}