Why does UIPageViewController's transition change the font?

时间:2015-07-28 15:45:11

标签: ios objective-c fonts ios8 uipageviewcontroller

I have an app that uses a UIPageViewController to present a quick guide on first launch. The UI is built in a storyboard - each page has the same nib and VC, but the text changes. The UILabels have a custom font (GothamRounded-Book) set in the Storyboard, which shows correctly in previews. However, they always display as the system font when running on a device.

After some investigation, I added an observer to the lable's font property, and it is changed at first appearance and whenever the page changes (Horizontal Scroll). Logging and stack traces below.

Why? How can I stop it?

viewDidLoad: <UICTFont: 0x14783630> font-family: \"GothamRounded-Book\"; font-weight: normal; font-style: normal; font-size: 17.00pt

viewDidAppear: <UICTFont: 0x14783630> font-family: \"GothamRounded-Book\"; font-weight: normal; font-style: normal; font-size: 17.00pt

change: {
    kind = 1;
    new = "<UICTFont: 0x1478ab40> font-family: \".HelveticaNeueInterface-Regular\"; font-weight: normal; font-style: normal; font-size: 14.00pt";
    old = "<UICTFont: 0x14783630> font-family: \"GothamRounded-Book\"; font-weight: normal; font-style: normal; font-size: 17.00pt";
}

frame #1: 0x2b2d8eba Foundation`NSKeyValueNotifyObserver + 262
...
frame #6: 0x2b2f834e Foundation`-[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 310
frame #7: 0x2e053d20 UIKit`-[_UIAttributeTraitStorage applyRecordsMatchingTraitCollection:] + 296
frame #8: 0x2e053518 UIKit`-[NSObject(_UITraitStorageAccessors) _applyTraitStorageRecordsForTraitCollection:] + 164
frame #9: 0x2df6ade2 UIKit`-[UIView _traitCollectionDidChangeFromOldCollection:toNewCollection:scaleDidChange:] + 58
frame #10: 0x2df6aea0 UIKit`-[UIView _wrappedProcessDidChangeRecursivelyFromOldTraits:toCurrentTraits:scaleDidChange:forceNotification:] + 128
frame #11: 0x2df6b0a0 UIKit`__86-[UIView _processDidChangeRecursivelyFromOldTraits:toCurrentTraits:forceNotification:]_block_invoke + 44
frame #12: 0x2e2fe830 UIKit`-[UIView(AdditionalLayoutSupport) _withUnsatisfiableConstraintsLoggingSuspendedIfEngineDelegateExists:] + 120
frame #13: 0x2df6b068 UIKit`-[UIView _processDidChangeRecursivelyFromOldTraits:toCurrentTraits:forceNotification:] + 252
frame #14: 0x2dccafae UIKit`-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 510
frame #15: 0x2d6ded28 QuartzCore`-[CALayer layoutSublayers] + 128
frame #16: 0x2d6da55c QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 360
frame #17: 0x2d6da3e4 QuartzCore`CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 16
frame #18: 0x2d6d9d80 QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 224
frame #19: 0x2d6d9b6e QuartzCore`CA::Transaction::commit() + 434
frame #20: 0x2d6d3848 QuartzCore`CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 56
frame #21: 0x2a616fec CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 20
...
frame #28: 0x000fc840 MyApp`main(argc=1, argv=0x014a2a74) + 108 at main.m:14

Label properties

1 个答案:

答案 0 :(得分:3)

  

为什么?

字体自动调整功能不适用于自定义字体,这包括使用大小类或自动收缩设置。如果未使用大小类,则autshrink无效。如果使用大小类,则自动收缩始终处于活动状态,并将字体重置为系统字体。我测试了Xcode 6.4和Xcode 7b3。

  

我该如何阻止它?

如果使用任何动态字体大小调整,则仅在故事板中使用系统字体。 覆盖viewDidLayoutSubviews以设置您真正想要的字体。如果自定义字体的大小调整属性与系统字体明显不同,则需要对计算的大小添加更正。

- (void)viewDidLayoutSubviews {
    self.myLabel.font = [UIFont fontWithName:@"Custom" size:self.myLabel.font.pointSize];
}