[英]iOS: CTFramesetterCreateWithAttributedString causes EXC_BAD_ACCESS, any guesses why?
I created a method to generate an attributed string from a normal string. 我创建了一种从普通字符串生成属性字符串的方法。 The attrString
value below is non-null and correct in its content. 下面的attrString
值非空且内容正确。
Upon running my application, the second line fails with an EXC_BAD_ACCESS
. 运行我的应用程序后,第二行失败,显示EXC_BAD_ACCESS
。 Any idea why? 知道为什么吗?
The __bridge_retained
call is an iOS 5 requirement afaik. __bridge_retained
调用是iOS 5要求afaik。 I've also tried __bridge
but that has no effect, the issue still occurs. 我也尝试过__bridge
但是没有效果,问题仍然存在。
NSMutableAttributedString *attrString = (NSMutableAttributedString*)[textLayer attributedString];
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((__bridge_retained CFMutableAttributedStringRef)attrString);
UPDATE 更新
If I do: 如果我做:
NSMutableAttributedString *attrString = (NSMutableAttributedString*)[textLayer attributedString];
NSLog(@"%@", attrString);
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((__bridge CFMutableAttributedStringRef)attrString);
Then the NSLog
line won't compile; 这样, NSLog
行将无法编译; Xcode gives a warning and error stating "Incompatible pointer types passing 'char[3]' to parameter of type 'NSString *'"
. Xcode给出警告和错误,指出"Incompatible pointer types passing 'char[3]' to parameter of type 'NSString *'"
。
So I tried this instead: 所以我尝试这样做:
NSLog([attrString description]);
And this gives the following output (I've replaced the string contents with <snipped>
for privacy) : 这给出了以下输出(出于隐私目的,我已将字符串内容替换为<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)}"; }
I noticed this in your attributed string dump: 我在属性字符串转储中注意到了这一点:
NSFont = "<CGFont (0x28f850): ArialMT>"
Did you create the attributed string using a CGFontRef
as the value for the kCTFontAttributeName
key? 您是否使用CGFontRef
作为kCTFontAttributeName
键的值来创建属性字符串? You must use a CTFontRef
, not a CGFontRef
. 您必须使用CTFontRef
,而不是CGFontRef
。 They are different. 他们是不同的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.