iOS 13需要注意的新特性

1.ios13之后模态视图默认样式变成了缩放的分页样式,而之前是全屏样式。可以通过下面的方法进行设置

UIViewController *vc = [[UIViewController alloc] init];
self.modalPresentationStyle = UIModalPresentationFullScreen;
[self.navigationController presentViewController:vc animated:YES completion:nil];

如果您要跳转的控制器加了导航栏,可以用下面的方法

    UIViewController *vc = [[UIViewController alloc] init];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    nav.modalPresentationStyle = UIModalPresentationFullScreen;
    [self.navigationController presentViewController:nav animated:YES completion:nil];

2.Dark Mode暗黑模式

暗黑模式适配,需要适配颜色和图片,参考链接:https://www.jianshu.com/p/0da3b107f06c

3.Status Bar样式

UIStatusBarStyleDefault自动选择黑色或白色 //ios13新增
UIStatusBarStyleDarkContent文字黑色
UIStatusBarStyleLightContent文字白色

4.UIActivityIndicatorView加载视图

//原有
UIActivityIndicatorViewStyleGray 灰色
UIActivityIndicatorViewStyleWhite 白色
UIActivityIndicatorViewStyleWhiteLarge 白色(大型)
//废弃了之前的三种样式,现在只有下面两种样式了
UIActivityIndicatorViewStyleLarge (大型)
UIActivityIndicatorViewStyleMedium (中型)

5.iOS 13中不再允许使用 valueForKey、setValue:forKey: 等方法获取或设置私有属性,虽然编译可以通过,但是在运行时会直接崩溃。比如UISearchBar 不能获取其私有属性,可以直接获取其textfield

    UISearchBar *searchBar = [[UISearchBar alloc] init];
    UITextField *searchTextField;
    if (@available(iOS 13.0, *)) {
        searchTextField = searchBar.searchTextField;
    }else {
        searchTextField = [searchBar valueForKey:@"_searchField"];
    }

6.UISegmentedControl iOS13之前默认选中样式是带边框、且选中是蓝色的、只能点击选中。iOS13之后 默认是无边框、且字体色值变为灰色、且可以滑动选中。可进行如下设置

        //边框
        _segment.layer.borderColor = DefaultBtnColor.CGColor;
        _segment.layer.borderWidth = 1;
        if (@available(iOS 13.0, *)) {
        //文字和背景颜色
            [_segment setTitleTextAttributes:@{NSForegroundColorAttributeName:DefaultBtnColor} forState:UIControlStateNormal];
            [_segment setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]} forState:UIControlStateSelected];
            [_segment setBackgroundImage:[UIImage imageWithColor:[UIColor whiteColor]] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
            [_segment setBackgroundImage:[UIImage imageWithColor:DefaultBtnColor] forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
        } else {
            // Fallback on earlier versions
            _segment.tintColor = DefaultBtnColor;
        }
/// 生成一张纯色图片
/// @param color 颜色
+ (UIImage *)imageWithColor:(UIColor *)color{
    CGRect rect = CGRectMake(0, 0, 1, 1);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, color.CGColor);
    CGContextFillRect(context, rect);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

7.继续使用 UISearchDisplayController 会导致崩溃,ios8开始就推荐用UISearchController

8.MPMoviePlayerController 被弃用

在 iOS 9 之前播放视频可以使用 MediaPlayer.framework 中的MPMoviePlayerController类来完成,它支持本地视频和网络视频播放。在ios13中继续使用会抛出异常,使用 AVFoundation 里的 AVPlayer进行替换

9.LaunchImage 被弃用

从2020年4月开始,所有支持 iOS 13 的 App 必须提供 LaunchScreen.storyboard,否则将无法提交到 App Store 进行审批。

10.Xcode 11 创建的工程在低版本设备上运行黑屏

使用 Xcode 11 创建的工程,在iOS 13.0 以下的设备运行会出现黑屏。这是因为 Xcode 11 默认是会创建通过 UIScene 管理多个 UIWindow 的应用,工程中除了 AppDelegate 外会多一个 SceneDelegate.

解决方案就是在 AppDelegate 的头文件加上:

@property (strong, nonatomic) UIWindow *window;

11.使用 @available 导致旧版本 Xcode 编译出错,建议用下面的方法获取系统版本

[UIDevice currentDevice].systemVersion.floatValue

12.textfield.leftview

直接给 textfield.leftView 赋值一个 UILabel 对象,他的宽高会被 sizeToFit,而不是创建时的值。解决方法是嵌套一个UIView在赋值给textfield.leftview

参考文章:https://www.cnblogs.com/PeterWolf/p/11573099.html

                  https://www.jianshu.com/p/8183d086b931

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值