美文网首页
Xcode11&iOS13适配

Xcode11&iOS13适配

作者: Brice_Zhao | 来源:发表于2019-10-25 17:41 被阅读0次

iOS夜间模式开发探索(iOS13)

原文链接:https://www.jianshu.com/p/f31f208313dd

私有API被封禁(KVC限制),禁止访问.

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

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

(1).获取SearchBar的textField

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

- (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];
}

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

3.Sign in with Apple 第三方登录
当 Sign In with Apple 服务正式上线以后,所有已接入其它第三方登录的 App,Sign In with Apple 将被要求作为一种登录选择,否则有可能就不给过。如果 APP 支持三方登陆(Facbook、Google、微信、QQ、支付宝等),就必须支持苹果登录,且要放前边。解决方法:未来上线之后,添加登录入口即可。

4.即将废弃的 LaunchImage
从 iOS 8 的时候,苹果就引入了 LaunchScreen,我们可以设置 LaunchScreen来作为启动页。当然,现在你还可以使用LaunchImage来设置启动图。不过使用LaunchImage的话,要求我们必须提供各种屏幕尺寸的启动图,来适配各种设备,随着苹果设备尺寸越来越多,这种方式显然不够 Flexible。而使用 LaunchScreen的话,情况会变的很简单, LaunchScreen是支持AutoLayout+SizeClass的,所以适配各种屏幕都不在话下。⚠️从2020年4月开始,所有使⽤ iOS13 SDK的 App将必须提供 LaunchScreen,LaunchImage即将退出历史舞台。可以使用Launch Storyboards来进行解决。

5.模态弹出默认交互改变
iOS 13 的 presentViewController 默认有视差效果,模态出来的界面现在默认都下滑返回。 一些页面必须要点确认才能消失的,需要适配。如果项目中页面高度全部是屏幕尺寸,那么多出来的导航高度会出现问题。

// Swift
self.modalPresentationStyle = .fullScreen
// Objective-C
self.modalPresentationStyle = UIModalPresentationFullScreen;

UIViewController 增加一个了属性 isModalInPresentation,默认为 false,当该属性为 false 时,用户下拉可以 dismiss 控制器,为 true 时,下拉不可以 dismiss控制器。

6.UISegmentedControl 默认样式改变
默认样式变为白底黑字,如果设置修改过颜色的话,页面需要修改

7.增加一直使用蓝牙的权限申请
CBCentralManager,iOS13以前,使用蓝牙时可以直接用,不会出现权限提示,iOS13后,再使用就会提示了。在info.plist里增加NSBluetoothAlwaysUsageDescription 我们要一直使用您的蓝牙,具体做什么别问我

8.废弃 UISearchDisplayController
在 iOS 8 之前,我们在 UITableView 上添加搜索框需要使用 UISearchBar + UISearchDisplayController 的组合方式,而在 iOS 8 之后,苹果就已经推出了 UISearchController 来代替这个组合方式。在 iOS 13 中,如果还继续使用 UISearchDisplayController 会直接导致崩溃,

未完待续…

相关文章

  • 适配xcode11&ios13

    Swift Packages 目前Pod跟SPM的兼容还没做好,配置好SPM后,Pod不能进行正常更新,先配置好P...

  • Xcode11&iOS13适配

    iOS夜间模式开发探索(iOS13) 原文链接:https://www.jianshu.com/p/f31f208...

  • 适配iOS11,适配iPhoneX,适配安全区的几个文章和宏

    适配iOS11,适配iPhoneX,适配安全区的几个文章和宏 适配iOS11,适配iPhoneX,适配安全区的几个...

  • App适配

    布局适配 字体适配 软键盘适配

  • 版本适配

    屏幕适配 代码适配 Masonry UIView+AutoLayout 可视化适配 autoLayout 系统适配...

  • Android屏幕适配

    px适配; 百分比适配; 修改dp适配; 屏幕适配 布局适配使用wrap_content,match_parent...

  • 屏幕适配

    适配 什么是适配?适应、兼容各种不同的情况 iOS开发中的适配?系统适配针对不同版本的操作系统进行适配屏幕适配针对...

  • iOS 适配器模式

    适配器模式创建适配协议,创建抽象适配器类,创建类适配器/对象适配器。 应用,适用场景电源适配器,普通充电器(类适配...

  • iPhone X 适配 ( iOS 11适配 ) 打理刘海

    iPhone X 适配 ( iOS 11适配 ) 打理刘海 iPhone X 适配 ( iOS 11适配 ) 打理刘海

  • iOS设计模式 (五) 适配器模式

    适配器模式 iOS中的适配器模式,主要由目标协议,适配者,适配器三部分组成. 适配器模式分类 类适配器: 适配器是...

网友评论

      本文标题:Xcode11&iOS13适配

      本文链接:https://www.haomeiwen.com/subject/mmpdyctx.html