iOS13,Xcode11安装后变化和老项目兼容

1,首先是登录的界面出现了presentviewcontroller后就会导致半屏幕显示

 LoginViewController *loginCtrl = [[LoginViewController alloc ] init];
        UINavigationController *presentCtrl = [[UINavigationController alloc] initWithRootViewController:loginCtrl];

//这段代码很重要,modalPresentationStyle就是改变了跳转页的样式,是否是全屏页面
        presentCtrl.modalPresentationStyle = UIModalPresentationFullScreen;

        [self presentViewController:presentCtrl animated:YES completion:^{
        }];

2,对于新的版本后,老得代码多了SceneDelegate.h 和SceneDelegate.m文件,归结原因,苹果开发者平台把app的功能调用和界面UI调用分开来了,这是为了以后对一个界面显示多个app做准备,一个appDelegate能控制多个SceneDelegate。对于解决办法,可以把info.plist文件中把关于SceneDelegate的链接(Application Scene Manifest)去掉,然后删除SceneDelegate.h 和SceneDelegate.m文件,这样就可以跟更新版本前一样了

3,关于加载图像如果出现黑屏或者屏幕展示效果会有上下两道黑条,这是由于LaunchImage没法自动匹配当前的图片的Frame导致的,也可能是由于图片尺寸不对,导致获取不到图片的Frame,建议直接改用LaunchScreen来配置启动图片,不建议再去修改LaunchImage,苹果开发文档表示:2020年4月份将会取消LaunchImage的使用

4对于私有的kvc问题,主要体现在对textplacehoder的字体大小和颜色设置上,

//修改textField的占位符字体颜色
[textField setValue:[UIColor xxx] forKeyPath:@"_placeholderLabel.textColor"];

 iOS13中通过KVC方式来获取私有属性,有Carsh风险,尽量避免使用.比如我们常用的UITextFiled和UISearchController等,在iOS 13的searchbar添加了一个- (void)set_cancelButtonText:(NSString *)text方法,这个方法专门用来命中kvc,一旦命中就Crash

搜了搜,感觉这个回答的最好:

(1).获取SearchBar的textField

由于在13中把SearchBar中的textField直接暴露给开发者使用,无需在通过kvc获取。

扫描二维码关注公众号,回复: 8659924 查看本文章
- (UITextField *)sa_GetSearchTextFiled{
    if ([[[UIDevice currentDevice]systemVersion] floatValue] >=     13.0) {
        return self.searchTextField;
    }else{
    UITextField *searchTextField = [self valueForKey:@"_searchField"];
        return searchTextField;
    }
}

(2).修改TextFiled的占位符字体大小以及颜色,在iOS13中不能通过KVC来进行修改,可以通过其属性字符串来进行修改

UITextField *textfield = [[UITextField alloc]init];
NSMutableAttributedString *arrStr = [[NSMutableAttributedString alloc]initWithString:textfield.placeholder attributes:@{NSForegroundColorAttributeName : [UIColor redColor],NSFontAttributeName:[UIFont systemFontOfSize:12]}];
textfield.attributedPlaceholder = arrStr;

(3).获取SearchBar的cancleButton,由于searcBar的层级发生变化以及对象的局部变量,因为无法通过kvc的方式来获取

if ([[[UIDevice currentDevice]systemVersion] floatValue] >= 13.0) {
  for(id cc in [self.searchBar subviews]) {
    for (id zz in [cc subviews]) {
      for (id gg in [zz subviews]) {
        if([gg isKindOfClass:[UIButton class]]){
          UIButton *cancelButton = (UIButton *)gg;
          [cancelButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        }
      }
    }
  }
}else{
  UIButton*cancelButton = (UIButton *)[self.searchBar getVarWithName:@"_cancelButton"];
  [cancelButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
}

5,MPMoviePlayerController在iOS13中废弃

MPMoviePlayerController is no longer available. Use AVPlayerViewController in AVKit.
在iOS13中对于MPMoviePlayerController使用的废弃,需要使用AVKit中的AVPlayerViewController来达到播放的目的。

6,增加一直使用蓝牙的权限申请

CBCentralManager,iOS13以前,使用蓝牙时可以直接用,不会出现权限提示,iOS13后,再使用就会提示了。在info.plist里增加NSBluetoothAlwaysUsageDescription

 7,(很新)iOS夜间模式开发探索(iOS13)

override func viewDidLoad() {
        super.viewDidLoad()

        // Always adopt a light interface style.    
        overrideUserInterfaceStyle = .light
}

以后继续更新...........

发布了16 篇原创文章 · 获赞 0 · 访问量 3079

猜你喜欢

转载自blog.csdn.net/meacholxpf/article/details/103237129