objective-c - NSString sizeWithAttributes在iOS 12上崩溃

标签 objective-c crash ios12

我最近在使用歌词组件时遇到了一个奇怪的崩溃。语言是Objective-C。这场愚蠢的崩溃使我困扰了很多天。

这是代码:

CGFloat charWidth = [character.character sizeWithAttributes:@{NSFontAttributeName:displayFont}].width;

和我的崩溃日志堆栈:
0 CoreText 0x0000000234f09938 __ZNK12TSplicedFont23GetOpticalSizeComponentEd + 148
1 CoreText 0x0000000234e7ffcc __ZL28DerivedOpticalFontDescriptorPK18__CTFontDescriptorPK9TBaseFontd + 120
2 CoreText 0x0000000234e88008 __ZN12TFontCascade26InitCascadeFallbackAtIndexElRj + 252
3 CoreText 0x0000000234e87a70 __ZNK12TFontCascade14CreateFallbackEPK8__CTFontPK10__CFString13CTEmojiPolicy + 728
4 CoreText 0x0000000234e54e40 __ZN13TGlyphEncoder21AppendUnmappedCharRunEjR6TCFRefIP5CTRunEPK8__CTFontR7CFRangeS8_R10TGlyphListI18TDeletedGlyphIndexESD_RK12TFontCascadeNS_15ClusterMatchingEb + 704
5 CoreText 0x0000000234e54900 __ZN13TGlyphEncoder28RunUnicodeEncoderRecursivelyEjO6TCFRefIP5CTRunEPK8__CTFont7CFRangeR10TGlyphListI18TDeletedGlyphIndexESC_PK12TFontCascadeNS_15ClusterMatchingEb + 1900
6 CoreText 0x0000000234e54114 __ZN13TGlyphEncoder17RunUnicodeEncoderEO6TCFRefIP5CTRunEPK8__CTFont7CFRangeR10TGlyphListI18TDeletedGlyphIndexEPK12TFontCascade + 128
7 CoreText 0x0000000234e53c30 __ZN13TGlyphEncoder11EncodeCharsE7CFRangeRK11TAttributesNS_9FallbacksE + 1240
8 CoreText 0x0000000234e6acb0 __ZN21TTypesetterAttrString10InitializeEPK20__CFAttributedString + 304
9 CoreText 0x0000000234e6ab6c __ZN21TTypesetterAttrStringC2EPK20__CFAttributedStringPK14__CFDictionary + 200
10 CoreText 0x0000000234e58070 CTLineCreateWithAttributedString + 60
11 UIFoundation 0x000000023b72be2c -[NSCoreTypesetter _stringDrawingCoreTextEngineWithOriginalString:rect:padding:context:forceClipping:styledTextOptions:attributes:stringDrawingOptions:drawingContext:wantsTextLineFragments:validatedAttributedString:firstNonRenderedCharacterIndex:foundSoftHyphenAtEOL:enginePathUsed:] + 1344
12 UIFoundation 0x000000023b7aae38 ___NSStringDrawingEngine + 3104
13 UIFoundation 0x000000023b72eb04 -[NSString(NSExtendedStringDrawing) boundingRectWithSize:options:attributes:context:] + 160
14 UIFoundation 0x000000023b7307dc -[NSString(NSStringDrawing) sizeWithAttributes:] + 120

最佳答案

我已经解决了这个问题。此方法必须在主线程中调用– JethroYe

关于objective-c - NSString sizeWithAttributes在iOS 12上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53774590/

相关文章:

iphone - 伪私有(private)方法的实现文件中的方法原型(prototype)?

objective-c - SBJSON 将新数据附加到现有 JSON 文件中,而不先解析它

swift - 如何 NSKeyedUnarchiver.unarchiveObject

ios - 从锁定的设备启动 CarPlay 音频应用程序时无法启动

iOS 12 - oneTimeCode OTP 委托(delegate)

ios - URL连接ios

Objective-C 错误 : Property 'active' is a scalar type on class 'Routine' . 无法为其生成 getter 方法

java - Android 上隐藏键盘会导致应用程序崩溃

crash - Android Studio 卡住

python - 当我开始打字时 PyCharm 崩溃