runtime解决iOS11 tableview上移下移问题
给tableview创建一个分类,然后交换初始化方法
#import "UITableView+Ex.h"
@implementation UITableView (Ex)
+(void)load{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
SEL originalSelector = @selector(initWithFrame:style:);
SEL swizzledSelector = @selector(mr_tableView_initWithFrame:style:);
Method originalMethod = class_getInstanceMethod([self class], originalSelector);
Method swizzledMethod = class_getInstanceMethod([self class], swizzledSelector);
BOOL didAddMethod = class_addMethod([self class], swizzledSelector,method_getImplementation(swizzledMethod) , method_getTypeEncoding(swizzledMethod));
if (didAddMethod)
{
class_replaceMethod([self class], swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
}
else
{
method_exchangeImplementations(originalMethod, swizzledMethod);
}
});
}
-(instancetype)mr_tableView_initWithFrame:(CGRect)frame style:(UITableViewStyle)style{
UITableView *tableview = [self mr_tableView_initWithFrame:frame style:style];
if (tableview) {
if (@available(iOS 11.0, *)) {
tableview.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
}
return tableview;
}
@end
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。