以下是iOS13一些適配問題的暫時解決方案儡羔,整理以下宣羊,希望能幫到大家。
UITextField 異常
在設(shè)置leftView 左按鈕時汰蜘,如果使用的是UIImageView仇冯,UIImageView的大小會自動根據(jù)圖片大小自動縮放內(nèi)容大小,即會出現(xiàn)圖片無法按照意圖顯示的問題
// Confuse in iOS13
UIImageView *imageIcon = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 40, 20)];
//search_icon 19*19
imageIcon.image = [UIImage imageNamed:@"search"];
imageIcon.contentMode = UIViewContentModeCenter;
UITextField *txtSearch = [[UITextField alloc] init];
txtSearch.leftView = imageIcon;
解決方案
- 方案一鉴扫、讓UI重新給一套圖吧,按照40 * 20 來給就行了
- 方案二赞枕、不使用UIImageView做為leftView
UIImageView *imageIcon = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 40, 20)];
//search 19*19
UIView *leftView = [UIView.alloc initWithFrame:CGRectMake(0, 0, 40, 20)];
UIView *contView = [UIView.alloc initWithFrame:CGRectMake(12, 1, 19, 19)];
contView.backgroundColor = [UIColor colorWithPatternImage:ASImage(@"search")];
UITextField *txtSearch = [[UITextField alloc] init];
txtSearch.leftView = imageIcon;
UITextField 通過KVC方式修改空白提示語顏色 崩潰
iOS13中,無法使用KVC修改占位文字的顏色,使用此方式會閃退
[UITextField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor”];
解決方案
- 使用富文本設(shè)置UITextField.attributedPlaceholder
控制器模態(tài)跳轉(zhuǎn)異常
iOS新增模態(tài)方式UIModalPresentationAutomatic,并且修改過場動畫上下文機制坪创,默認(rèn)調(diào)整為了卡片樣式炕婶。
typedef NS_ENUM(NSInteger, UIModalPresentationStyle) {
UIModalPresentationFullScreen = 0,
UIModalPresentationPageSheet API_AVAILABLE(ios(3.2)) API_UNAVAILABLE(tvos),
UIModalPresentationFormSheet API_AVAILABLE(ios(3.2)) API_UNAVAILABLE(tvos),
UIModalPresentationCurrentContext API_AVAILABLE(ios(3.2)),
UIModalPresentationCustom API_AVAILABLE(ios(7.0)),
UIModalPresentationOverFullScreen API_AVAILABLE(ios(8.0)),
UIModalPresentationOverCurrentContext API_AVAILABLE(ios(8.0)),
UIModalPresentationPopover API_AVAILABLE(ios(8.0)) API_UNAVAILABLE(tvos),
UIModalPresentationBlurOverFullScreen API_AVAILABLE(tvos(11.0)) API_UNAVAILABLE(ios) API_UNAVAILABLE(watchos),
UIModalPresentationNone API_AVAILABLE(ios(7.0)) = -1,
UIModalPresentationAutomatic API_AVAILABLE(ios(13.0)) = -2,
};
解決方案
- 方案一、如果項目中控制器模態(tài)跳轉(zhuǎn)不多,可一個個修改,設(shè)定vc.modalPresentationStyle = UIModalPresentationFullScreen即可
- 方案二莱预、如果項目中模態(tài)過多或者使用的cocoaPod繼承的第三方中也存在此問題而第三方?jīng)]有維護更新柠掂;可使用運行時交換系統(tǒng)方法處理
#import "UIViewController+Presented.h"
@implementation UIViewController (Presented)
+ (void)load {
vpswizzleMethod([self class], @selector(presentViewController:animated:completion:), @selector(swizzled_presentViewController:animated:completion:));
}
- (void)swizzled_presentViewController:(UIViewController *)vc animated:(BOOL)animated completion:(void (^)(void))completion {
// 屏蔽iOS13 模態(tài)半推框 導(dǎo)致vc聲明周期不調(diào)用造成程序邏輯丟失的問題
vc.modalPresentationStyle = UIModalPresentationFullScreen;
[self swizzled_presentViewController:vc animated:animated completion:completion];
}
void vpswizzleMethod(Class class, SEL originalSelector, SEL swizzledSelector) {
Method originalMethod = class_getInstanceMethod(class, originalSelector);
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
BOOL didAddMethod = class_addMethod(class, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod));
if (didAddMethod) {
class_replaceMethod(class, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
} else {
method_exchangeImplementations(originalMethod, swizzledMethod);
}
}
@end