ios - 使用 coretext,在绘制图像和在 ios6 中,我得到 CTFrame 空值

标签 ios ios6

CTFrame:可见字符串范围 = (0, 0){type = mutable-small, count = 0, values = ()}

我发现这个问题只发生在 ios6 中,并且只绘制图像。最终,我发现这段代码可能是问题所在:

if (imagename) {

    //render empty space for drawing the image in the text //1
    CTRunDelegateCallbacks callbacks;
    callbacks.version = kCTRunDelegateVersion1;
    callbacks.getAscent = ascentCallback;
    callbacks.getDescent = descentCallback;
    callbacks.getWidth = widthCallback;
    callbacks.dealloc = deallocCallback;

    NSDictionary *imgAttr = @{@"width": [NSNumber numberWithFloat:self.customFaceSize.width],
                              @"height": [NSNumber numberWithFloat:self.customFaceSize.height],
                              @"descent" : [NSNumber numberWithFloat:0],
                              };

    CFRetain((__bridge CFTypeRef)imgAttr); 
    CTRunDelegateRef delegate = CTRunDelegateCreate(&callbacks, (__bridge void *)(imgAttr));
    NSDictionary *attrDictionaryDelegate = [NSDictionary dictionaryWithObjectsAndKeys:
                                            (__bridge id)delegate,(NSString *)kCTRunDelegateAttributeName,
                                            imagename,iCKeyFaceName,
                                            [NSNumber numberWithLong:styleRange.location],iCkeyFaceLocation,
                                            nil];
    [*attributedString addAttributes:attrDictionaryDelegate range:styleRange];
    [*attributedString addAttributes:[self attributesWithNude:nude] range:styleRange];
}else{

    [*attributedString addAttributes:[self attributesWithNude:nude] range:styleRange];
}

我该怎么办?谢谢

最佳答案

我解决了这个问题,我发现 ios6 中的路径矩形有所不同。

CGRect drawingRect = self.bounds;
CGPathAddRect(path, NULL, drawingRect);
CTFrameRef textFrame = CTFramesetterCreateFrame(framesetter,CFRangeMake(0,0), path, NULL);

drawingRect.size.height小于ios7及以上

so.i通过在ios6中为drawingRect.size.height添加小像素来修复它,并且它可以工作。 希望对你有帮助。

drawingRect.size.height += 2;

关于ios - 使用 coretext,在绘制图像和在 ios6 中,我得到 CTFrame 空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24602187/

相关文章:

objective-c - 推送 View Controller 时如何隐藏导航栏?

iphone - 每个单元格中有多个项目的 UITableView

ios - 图像不显示在 Firebase 的表格单元格中

iphone - 在导航 View Controller 中加载特定场景

ios - 它不允许我创建导出

objective-c - iCloud文件上传错误(NSFileWriteNoPermissionError = 513)

ios - CoreImage 的深度/透视?

ios - 如何在同一 Controller 中交替切换 View ( View 需要遍布屏幕)?

android - 如何使用 Google Play 服务 C++ 实现前 10 名排行榜

ios - 无法对下载到数组中的值求和