IOS13升级后接到好多用户反馈,也有自己发现的,整理一下,希望能帮助大家。
在设置leftView 左按钮时,如果使用的是UIImageView,UIImageView的大小会自动根据图片大小自动缩放内容大小,即会出现图片无法按照意图显示的问题
UIImageView* view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
UIImageView* headImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 20, 20)];
headImageView.image = [[UIImage imageNamed:@"task_response_by_spec"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
headImageView.tintColor = [UIColor whiteColor];
[view addSubview:headImageView];
_uesrNameTextField.leftView = view;
_uesrNameTextField.leftViewMode = UITextFieldViewModeAlways;
_uesrNameTextField.textColor = [UIColor whiteColor];
[self.view addSubview:_uesrNameTextField];
使用View来代替UIImageView作为LeftView
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0,0,_uesrNameTextField.height,_uesrNameTextField.height)];
UIImageView *headImageView = [[UIImageView alloc] initWithFrame:CGRectMake(12.5, 12.5, 20, 20)];
headImageView.image = [[UIImage imageNamed:@"task_response_by_spec"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
headImageView.tintColor = [UIColor whiteColor];
[view addSubview:headImageView];
_uesrNameTextField.backgroundColor = [[UIColor colorWithHexString:@"424d5a"] colorWithAlphaComponent:0.7];
_uesrNameTextField.leftView = view;
_uesrNameTextField.leftViewMode = UITextFieldViewModeAlways;
_uesrNameTextField.textColor = [UIColor whiteColor];
[self.view addSubview:_uesrNameTextField];
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,
};
#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 模态半推框 导致vc声明周期不调用造成程序逻辑丢失的问题
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
[UITextField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor”];
UICollectionView 注册资源registerNib位置滞后iOS13中出现崩溃
此崩溃是在一个第三方库TZImagePickerController出现的。
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(margin, top, self.view.tz_width - 2 * margin, self.view.tz_height - 50 - top) collectionViewLayout:layout];
_collectionView.backgroundColor = [UIColor whiteColor];
_collectionView.dataSource = self;
_collectionView.delegate = self;
_collectionView.alwaysBounceHorizontal = NO;
if (iOS7Later) _collectionView.contentInset = UIEdgeInsetsMake(0, 0, 0, 2);
_collectionView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 0, -2);
_collectionView.contentSize = CGSizeMake(self.view.tz_width, ((_model.count + 3) / 4) * self.view.tz_width);
[self.view addSubview:_collectionView];
[_collectionView registerNib:[UINib nibWithNibName:@"TZAssetCell" bundle:nil] forCellWithReuseIdentifier:@"TZAssetCell"];
解决方案
把注册的代码提前到UICollectionView初始化后
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(margin, top, self.view.tz_width - 2 * margin, self.view.tz_height - 50 - top) collectionViewLayout:layout];
//注册nib位置提前,否则在iOS13上报错
[_collectionView registerNib:[UINib nibWithNibName:@"TZAssetCell" bundle:nil] forCellWithReuseIdentifier:@"TZAssetCell"];
_collectionView.backgroundColor = [UIColor whiteColor];
_collectionView.dataSource = self;
_collectionView.delegate = self;
_collectionView.alwaysBounceHorizontal = NO;
if (iOS7Later) _collectionView.contentInset = UIEdgeInsetsMake(0, 0, 0, 2);
_collectionView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 0, -2);
_collectionView.contentSize = CGSizeMake(self.view.tz_width, ((_model.count + 3) / 4) * self.view.tz_width);
[self.view addSubview:_collectionView];