我在 UIVIew 中绘制了一些文本drawRect:
。首先我计算文本高度,然后drawInRect:
。下面的代码有效:
- (void)drawRect:(CGRect)rect
{
CGFloat titleHeight = [self heightForText:_entry.title
withFont:[UIFont systemFontOfSize:12.0f]];
CGRect r = CGRectMake(54, 6, kCellTextWidth, titleHeight);
[_entry.title drawInRect:r withFont:[UIFont titleFont]];
}
dispatch_async
然后我用main_queue中的drawInRect计算文本高度,它失败了:
- (void)drawRect:(CGRect)rect
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
CGFloat titleHeight = [self heightForText:_entry.title
withFont:[UIFont systemFontOfSize:12.0f]];
dispatch_async(dispatch_get_main_queue(), ^{
CGRect r = CGRectMake(54, 6, kCellTextWidth, titleHeight);
[_entry.title drawInRect:r withFont:[UIFont titleFont]];
});
});
}
错误:
<Error>: CGContextSetFont: invalid context 0x0
<Error>: CGContextSetTextMatrix: invalid context 0x0
<Error>: CGContextSetFontSize: invalid context 0x0
<Error>: CGContextSetTextPosition: invalid context 0x0
<Error>: CGContextShowGlyphsWithAdvances: invalid context 0x0
错误是什么意思?如何计算另一个线程中的文本高度以提高速度?
谢谢你。