CTFontRef未显示在ios 7.1.2

时间:2015-09-03 10:50:41

标签: ios objective-c nsattributedstring core-text uifont

我使用CoreText在我的应用程序中加载和显示自定义字体(120附近的字体数) 应用程序中有一个带有字体列表的表 在表格中任何显示自定义字体的行 我加载字体:

CFArrayRef descriptors = CTFontManagerCreateFontDescriptorsFromURL((CFURLRef)_fontURL);
        if (descriptors)
        {
            CTFontDescriptorRef fontDescriptor = CFArrayGetValueAtIndex(descriptors, 0);
            CTFontRef createdFont = CTFontCreateWithFontDescriptor(fontDescriptor, 20.0, NULL);
            self.font = createdFont;
            if (createdFont)
            {
                CTFontManagerRegisterFontsForURL((CFURLRef)_fontURL, kCTFontManagerScopeProcess, &error);               
                CFRelease(createdFont);
            }
            CFRelease(descriptors);
        }

此代码更正适用于除7.1.2之外的任何iOS版本。 7.1.2中存在一个奇怪的问题 当我滚动表格时,某些字体不会显示或显示不正确的字符。 (有时在滚动的日志时间后出现此问题)
此问题仅出现在7.1.2上。

我尝试了什么:
    1.我尝试将所有字体添加到plist文件的UIAppFonts中,但它没有帮助。但我知道如果我添加更多114字体,那么应用程序将崩溃     我已经检查了字体的双重注册,但它也没有帮助     我检查过所有字体是从主线程加载的。

我所做的一切都没有帮助。在iOS 7.1.2中这种行为的原因是什么?
我会很高兴任何版本。

更新 4.09.215

如果我没有检查字体的双重注册,则会收到以下错误(对于不同的字体):

Error Domain=com.apple.coretext Code=104 "The operation couldn’t be completed. 
(com.apple.coretext error 104 - Could not register the font file 'file:///private/var/mobile/Applications/694011F5-A0F3-4A54-87B4-138F4ED8E781/AppName.app/fontsForEditor/LANEPOSH.ttf')" 
UserInfo=0x1754d6b0 {CTFailedFontFileURL=file:///private/var/mobile/Applications/694011F5-A0F3-4A54-87B4-138F4ED8E781/AppName.app/fontsForEditor/LANEPOSH.ttf,
NSDescription=Could not register the font file 'file:///private/var/mobile/Applications/694011F5-A0F3-4A54-87B4-138F4ED8E781/AppName.app/fontsForEditor/LANEPOSH.ttf'}

CTFontManagerCreateFontDescriptorsFromURL返回NULL。

如果我检查双重注册(例如,如果我打开此页面两次),我没有错误(因为我没有调用注册),但CTFontManagerCreateFontDescriptorsFromURL返回NULL。 我认为,当我第二次尝试 创建 CTFontDescriptiorRef时,就会发生这种情况。

我通过这种方式将字体设置为标签:

- (void)_updateLabelFont
{
    CFStringRef fontName = CTFontCopyPostScriptName(self.model.font);

    UIFont* font = [UIFont fontWithName:(__bridge NSString*)fontName size:FONT_SIZE];

    if (fontName)
    {
        CFRelease(fontName);
        fontName = NULL;
    }

    self.fontNameLabel.font = font;
}

此外,我试图将UILabel更改为TTTAttributedLabel(以避免创建UIFont实例),我收到了同样的效果。
我注意到如果我删除了字体的双重注册,那么问题会更快出现(我在用户触摸后重新创建单元格)。

0 个答案:

没有答案