美文网首页
基础知识点笔记

基础知识点笔记

作者: CrazySteven | 来源:发表于2021-03-13 21:29 被阅读0次

关于SceneDelegate的介绍网上已经有很多了,这里做个笔记来记录一下。

不使用SceneDelegate
  • 删除掉info.plist中Application Scene Manifest选项,同时,文件SceneDelegate可删除可不删
  • 注释或删除UISceneSession lifecycle的两个方法
  • 在AppDelegate.h中添加一个window属性
    @property (strong, nonatomic) UIWindow * window;
使用SceneDelegate
  • 在AppDelegate和SceneDelegate中使用@available(iOS 13, *)
  • 在AppDelegate.h中添加一个window属性
    @property (strong, nonatomic) UIWindow * window;
    然后写两套同样的逻辑,iOS13以下的走AppDelegate,iOS13以上的走SceneDelegate.

写代码的时候在模拟器上显示正常,到我真机上就出了问题,发现是app跟随系统深色主题,view,label等控件都变成了深色系


全局禁用深色模式(暗黑模式)

Info.plist中增加Appearance,值为Light

修改textfield的时候报错'Access to UITextField's _placeholderLabel ivar is prohibited. This is an application bug

以前的写法
[_nameTF setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
现在改成

#import <objc/message.h>
if (@available(iOS 13,*)){
  Ivar ivar =  class_getInstanceVariable([UITextField class], "_placeholderLabel");
  UILabel *placeholderLabel = object_getIvar(self.nameTF, ivar);
  placeholderLabel.textColor = [UIColor lightGrayColor];
}else {
  [_nameTF setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
}

M1芯片的电脑,若Xcode使用Rosetta打开,创建Viewxib文件可能会报错An internal error occured. Editing functionality may be limited
解决办法就是去掉Rosetta


清除模拟器缓存

  • 退出模拟器
  • 终端执行xcrun simctl erase all

后台返回数据<object returned empty description>
解决方法:
用string来接收,判断[string length] > 0即可


<NSLayoutConstraint:0x6000034b7980 UIView:0x7ff21de0ce00.width == - 16 (active)>
这个错误约束是用系统的UIAlertController出现的,从iOS12.1开始,到iOS14.4还没修复。。。无解

版权声明:本文为 Crazy Steven 原创出品,欢迎转载,转载时请注明出处!

相关文章

网友评论

      本文标题:基础知识点笔记

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