簡體   English   中英

iOS:CTFramesetterCreateWithAttributedString導致EXC_BAD_ACCESS,為什么會這樣呢?

[英]iOS: CTFramesetterCreateWithAttributedString causes EXC_BAD_ACCESS, any guesses why?

我創建了一種從普通字符串生成屬性字符串的方法。 下面的attrString值非空且內容正確。

運行我的應用程序后,第二行失敗,顯示EXC_BAD_ACCESS 知道為什么嗎?

__bridge_retained調用是iOS 5要求afaik。 我也嘗試過__bridge但是沒有效果,問題仍然存在。

    NSMutableAttributedString *attrString = (NSMutableAttributedString*)[textLayer attributedString];
    CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((__bridge_retained CFMutableAttributedStringRef)attrString);

更新

如果我做:

    NSMutableAttributedString *attrString = (NSMutableAttributedString*)[textLayer attributedString];
    NSLog(@"%@", attrString);
    CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((__bridge CFMutableAttributedStringRef)attrString);

這樣, NSLog行將無法編譯; Xcode給出警告錯誤,指出"Incompatible pointer types passing 'char[3]' to parameter of type 'NSString *'"

所以我嘗試這樣做:

    NSLog([attrString description]);

這給出了以下輸出(出於隱私目的,我已將字符串內容替換為<snipped>

2012-01-19 06:49:11.307 WritePath[2475:707] <Snipped> { CTForegroundColor = "<CGColor 0x281530> [<CGColorSpace 0x22d1a0> (kCGColorSpaceDeviceRGB)] ( 0 0 0 1 )"; NSFont = "<CGFont (0x28f850): ArialMT>"; NSParagraphStyle = "CTParagraphStyle:\\nwriting direction = -1, alignment = 3, line break mode = 0, default tab interval = 0\\nfirst line head indent = 0, head indent = 0, tail indent = 0\\nline height multiple = 0, maximum line height = 0, minimum line height = 0\\nline spacing adjustment = 0, paragraph spacing = 0, paragraph spacing before = 0\\ntabs:\\n<CFArray 0x287b50 [0x3f229630]>{type = immutable, count = 12, values = (\\n\\t0 : CTTextTab: location = 28, alignment = 0, options = (none)\\n\\n\\t1 : CTTextTab: location = 56, alignment = 0, options = (none)\\n\\n\\t2 : CTTextTab: location = 84, alignment = 0, options = (none)\\n\\n\\t3 : CTTextTab: location = 112, alignment = 0, options = (none)\\n\\n\\t4 : CTTextTab: location = 140, alignment = 0, options = (none)\\n\\n\\t5 : CTTextTab: location = 168, alignment = 0, options = (none)\\n\\n\\t6 : CTTextTab: location = 196, alignment = 0, options = (none)\\n\\n\\t7 : CTTextTab: location = 224, alignment = 0, options = (none)\\n\\n\\t8 : CTTextTab: location = 252, alignment = 0, options = (none)\\n\\n\\t9 : CTTextTab: location = 280, alignment = 0, options = (none)\\n\\n\\t10 : CTTextTab: location = 308, alignment = 0, options = (none)\\n\\n\\t11 : CTTextTab: location = 336, alignment = 0, options = (none)\\n\\n)}"; }

我在屬性字符串轉儲中注意到了這一點:

NSFont = "<CGFont (0x28f850): ArialMT>"

您是否使用CGFontRef作為kCTFontAttributeName鍵的值來創建屬性字符串? 您必須使用CTFontRef ,而不是CGFontRef 他們是不同的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM