我有一个部分用 Swift 3.2 编写的应用程序和使用 xcode 10 构建的 Objective-c,我在一些 Swift ViewControllers 中发生了奇怪的崩溃,在我收集的日志中,发生崩溃的那一行是我在 UILabel 上设置文本 (valueLabel.text = "-")(UILabel 是正常的,没有继承也没有任何自定义)。
Fatal Exception: NSInvalidArgumentException
0 CoreFoundation 0x212368ec4 __exceptionPreprocess
1 libobjc.A.dylib 0x211539a40 objc_exception_throw
2 CoreFoundation 0x21226f594 -[NSCache init]
3 UIKitCore 0x23f14fba0 (Missing)
4 UIKitCore 0x23f14fc3c (Missing)
5 UIFoundation 0x21c9ca778 attributeDictionaryHash
6 Foundation 0x212dc8074 hashProbe
7 Foundation 0x212ce5c24 -[NSConcreteHashTable getItem:]
8 UIFoundation 0x21c975548 +[NSAttributeDictionary newWithDictionary:]
9 UIFoundation 0x21c9778e4 -[_NSCachedAttributedString initWithString:attributes:]
10 UIFoundation 0x21c9e5b98 __NSStringDrawingEngine
11 UIFoundation 0x21c9697e4 -[NSString(NSExtendedStringDrawing) boundingRectWithSize:options:attributes:context:]
12 UIKitCore 0x23f90c9a0 (Missing)
18 ole-consignado 0x100e336ac $S14test_app18CardViewControllerC11resetLayout33_2E2D3FEF56CDB4998F73949398E4FE67LLyyF (CardViewController.swift:103)
19 ole-consignado 0x100e327b4 $S14test_app18CardViewControllerC17viewWillDisappearyySbF (CardViewController.swift:73)
20 ole-consignado 0x100e32804 $S14test_app18CardViewControllerC17viewWillDisappearyySbFTo (<compiler-generated>)
21 UIKitCore 0x23ef39068 (Missing)
43 CoreFoundation 0x2122f87cc __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__
44 CoreFoundation 0x2122f3460 __CFRunLoopDoObservers
45 CoreFoundation 0x2122f3a00 __CFRunLoopRun
46 CoreFoundation 0x2122f31f0 CFRunLoopRunSpecific
47 GraphicsServices 0x21456c584 GSEventRunModal
48 UIKitCore 0x23f4fad40 (Missing)
49 ole-consignado 0x100b37f74 main (main.m:14)
50 libdyld.dylib 0x211db2bb4 start
所以我的问题是有人之前遇到过那次崩溃并有解决方案建议吗?
最佳答案
每当您通过 UIColor.init
实例化 UIColor 时,都会生成 UIPlaceholderColor 的实例。 , 不需要参数。关于这个的事情是它在 UIKit 的语义中是完全有效的,并导致它显示为 UIColor.clear
, 大概。
突破点是尝试将它与 CoreGraphics 语义一起使用。 UIPlaceholderColor 的底层存储不具有颜色空间和任何颜色值存储,因此无法使用 cgColor
转换为 CGColor。 setter/getter 。 hash
getter 是同样的故事。
你如何解决这种情况?确定,你到底在哪里打电话UIColor.init
并将其替换为 UIColor.clear
,这将很容易转换为 CGColor。
关于ios - 未为 UIColor 定义散列 UIPlaceholderColor 需要先转换颜色空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53944569/