添加扩展类冷处理
+ (void)load{
SEL originalSelector = @selector(doesNotRecognizeSelector:);
SEL swizzledSelector = @selector(sw_doesNotRecognizeSelector:);
Method originalMethod = class_getClassMethod(self, originalSelector);
Method swizzledMethod = class_getClassMethod(self, swizzledSelector);
if(class_addMethod(self, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod))){
class_replaceMethod(self, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
}else{
method_exchangeImplementations(originalMethod, swizzledMethod);
}
}
+ (void)sw_doesNotRecognizeSelector:(SEL)aSelector{
//处理 _LSDefaults 崩溃问题
if([[self description] isEqualToString:@"_LSDefaults"] && (aSelector == @selector(sharedInstance))){
//冷处理...
return;
}
[self sw_doesNotRecognizeSelector:aSelector];
}
b.其他 问题可以直接更新友盟即可
+(void)load
{
Method present = class_getInstanceMethod(self, @selector(presentViewController:animated:completion:));
Method swizzNewPresent = class_getInstanceMethod(self, @selector(DJPresentViewController:Animated:completion:));
method_exchangeImplementations(present, swizzNewPresent);
}
-(void)DJPresentViewController:(UIViewController *)viewcontroller Animated:(BOOL)animated completion:(void (^)(void))completion{
if (@available(iOS 13.0, *)) {
viewcontroller.modalPresentationStyle = UIModalPresentationFullScreen;
[self DJPresentViewController:viewcontroller Animated:animated completion:completion];
}else{
[self DJPresentViewController:viewcontroller Animated:animated completion:completion];
}
}
a.建议pod 导入 升级repo
b.重新pod install 新版本4.0.0版本及以上都可以
c.本地有QMUIConfigurationTemplate文件报错 直接github上下载下来直接替换
a、UITextField 通过KVC方式修改空白提示语颜色 崩溃
[UITextField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor”];
解决
attributedPlaceholder
_textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"姓名" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14],NSForegroundColorAttributeName:[UIColor redColor]}];
b、leftView、rightView 设置出错
imageView 在 textfield.leftView 中宽高被 sizeToFit 了,imageView 中设置的宽高无效了。
(例如:rightView的子视图约束布局, 会导致rightView覆盖整个UITextField)
UIImageView *imageIcon = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 34, 30)];
imageIcon.image = [UIImage imageNamed:@"search_icon"];
imageIcon.contentMode = UIViewContentModeCenter;
// Confuse in iOS13 先添加一层view 再添加上去
UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 80, 50)];
leftView.backgroundColor = UIColor.clearColor;
[leftView addSubview:imageIcon];
UITextField *txtSearch = [[UITextField alloc] init];
txtSearch.leftView = leftView;
txtSearch.leftViewMode = UITextFieldViewModeAlways;
c、UISearchBar searchTextField 可以直接使用不用再次获取
(copy 原文地址)
#pragma mark - DarkMode Adapater
#ifdef __IPHONE_13_0
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection{
[super traitCollectionDidChange:previousTraitCollection];
if (@available(iOS 13.0, *)) {
if([UITraitCollection.currentTraitCollection hasDifferentColorAppearanceComparedToTraitCollection:previousTraitCollection]){
[self.layer setNeedsDisplay];
}
} else {
// Fallback on earlier versions
}
}
#endif
#pragma mark - Dark mode Adapter
#ifdef __IPHONE_13_0
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection{
[super traitCollectionDidChange:previousTraitCollection];
if (@available(iOS 13.0, *)) {
if([UITraitCollection.currentTraitCollection hasDifferentColorAppearanceComparedToTraitCollection:previousTraitCollection]){
[self _commitUpdate];
}
} else {
// Fallback on earlier versions
}
}
#endif
- (void)setColor:(UIColor *)color {
[self setColor:color range:NSMakeRange(0, self.length)];
}
- (void)setStrokeColor:(UIColor *)strokeColor {
[self setStrokeColor:strokeColor range:NSMakeRange(0, self.length)];
}
- (void)setStrikethroughColor:(UIColor *)strikethroughColor {
[self setStrikethroughColor:strikethroughColor range:NSMakeRange(0, self.length)];
}
- (void)setUnderlineColor:(UIColor *)underlineColor {
[self setUnderlineColor:underlineColor range:NSMakeRange(0, self.length)];
}
[tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
RGB(146, 146, 146), NSForegroundColorAttributeName,
[UIFont boldSystemFontOfSize:10.0f], NSFontAttributeName,
nil] forState:UIControlStateNormal];
此方法设置颜色无效 更改为:
[[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:RGB(252,50,79)} forState:UIControlStateSelected];
或者是
UITabBarAppearance *tabBarAppearance = [[UITabBarAppearance alloc] init];
tabBarAppearance.stackedLayoutAppearance.selected.titleTextAttributes = @{NSForegroundColorAttributeName:RGB(252,50,79)};
[[UITabBar appearance] setStandardAppearance:tabBarAppearance];
Xcode自动新增了一个SceneDelegate文件,查找了一下官方文档WWDC2019:Optimizing App Launch
iOS13之前,Appdelegate的职责全权处理App生命周期和UI生命周期;
iOS13之后,Appdelegate的职责是:
1、处理 App 生命周期
2、新的 Scene Session 生命周期
那UI的生命周期呢?交给新增的Scene Delegate处理
用图表示就是:
iOS13之前:
这种模式完全没问题,因为只有一个进程,只有一个与这个进程对应的用户界面
但是iOS13之后,Appdelegate不在负责UI生命周期,所有UI生命周期交给SceneDelegate处理:
因此初始化window方法需要改变:
现在不再Appdelegate的 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 进行初始化,转交给SceneDelegate的 willConnectToSession: 方法进行根控制器设置:
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
UIWindowScene *windowScene = (UIWindowScene *)scene;
self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
self.window.frame = windowScene.coordinateSpace.bounds;
self.window.rootViewController = [UITabBarController new];
[self.window makeKeyAndVisible];
}