iOS13 App适配

1. 设置不响应黑暗模式

Info.plist中添加以下代码

    UIUserInterfaceStyle
    Light
Info.plist

2. 字体适配

iOS13中获取系统字体的fontName,得到的是并没有什么用的 romannewtime字体.
建议使用

+ (UIFont *)systemFontOfSize:(CGFloat)fontSize weight:(UIFontWeight)weight API_AVAILABLE(ios(8.2));

// Suggested values for use with UIFontWeightTrait, and UIFont's systemFontOfSize:weight:
// Beware that most fonts will _not_ have variants available in all these weights!
UIKIT_EXTERN const UIFontWeight UIFontWeightUltraLight API_AVAILABLE(ios(8.2));
UIKIT_EXTERN const UIFontWeight UIFontWeightThin API_AVAILABLE(ios(8.2));
UIKIT_EXTERN const UIFontWeight UIFontWeightLight API_AVAILABLE(ios(8.2));
UIKIT_EXTERN const UIFontWeight UIFontWeightRegular API_AVAILABLE(ios(8.2));
UIKIT_EXTERN const UIFontWeight UIFontWeightMedium API_AVAILABLE(ios(8.2));
UIKIT_EXTERN const UIFontWeight UIFontWeightSemibold API_AVAILABLE(ios(8.2));
UIKIT_EXTERN const UIFontWeight UIFontWeightBold API_AVAILABLE(ios(8.2));
UIKIT_EXTERN const UIFontWeight UIFontWeightHeavy API_AVAILABLE(ios(8.2));
UIKIT_EXTERN const UIFontWeight UIFontWeightBlack API_AVAILABLE(ios(8.2));

3. 弹出样式

/*
 Defines the presentation style that will be used for this view controller when it is presented modally. Set this property on the view controller to be presented, not the presenter.
 If this property has been set to UIModalPresentationAutomatic, reading it will always return a concrete presentation style. By default UIViewController resolves UIModalPresentationAutomatic to UIModalPresentationPageSheet, but system-provided subclasses may resolve UIModalPresentationAutomatic to other concrete presentation styles. Participation in the resolution of UIModalPresentationAutomatic is reserved for system-provided view controllers.
 Defaults to UIModalPresentationAutomatic on iOS starting in iOS 13.0, and UIModalPresentationFullScreen on previous versions. Defaults to UIModalPresentationFullScreen on all other platforms.
 */
@property(nonatomic,assign) UIModalPresentationStyle modalPresentationStyle API_AVAILABLE(ios(3.2));

因此我们的方案是在BaseViewController中,指定样式为全屏,两个时机:

  • 初始化的时候
  • 调用弹起时
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        self.modalPresentationStyle = UIModalPresentationFullScreen;
    }
    return self;
}

- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^ __nullable)(void))completion {
    if (@available(iOS 13.0, *)) {
        if (viewControllerToPresent.modalPresentationStyle == UIModalPresentationPageSheet) {
            viewControllerToPresent.modalPresentationStyle = UIModalPresentationFullScreen;
        }
    }

    [super presentViewController:viewControllerToPresent animated:flag completion:completion];
}

4. UITabBar样式

  • 字体颜色异常(显示蓝色)
//iOS 13中需设置
if (@available(iOS 13.0, *)) {
    self.tabBar.tintColor = Red_COLOR;
    self.tabBar.unselectedItemTintColor = 66_66_66_COLOR;
}
  • Gif显示异常(灰块)
// 需要将gif的每一帧设置为 UIImageRenderingModeAlwaysOriginal 
    if (@available(iOS 13.0, *)) {
        NSArray *sourceInsideImages = [tabImage images];
        NSMutableArray *insideImages = [[NSMutableArray alloc] initWithCapacity:0];
        for (UIImage *sourceImage in sourceInsideImages) {
            UIImage *insideImage = [sourceImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
            [insideImages addObject:insideImage];
        }
        tabImage = [UIImage animatedImageWithImages:insideImages duration:tabImage.duration];
    }
  • 隐藏头部线条
        UITabBarAppearance *appearance = tabBar.standardAppearance.copy;
        appearance.shadowColor = [UIColor clearColor];
        appearance.shadowImage = [UIImage new];
        tabBar.standardAppearance = appearance;

你可能感兴趣的:(iOS13 App适配)