1、利用runtime方法交换机制 适配iOS11--contentInsetAdjustmentBehavior
#import "UIScrollView+PYExtension.h"
#import <objc/runtime.h>
@implementation UIScrollView (PYExtension)
+ (void)load {
Method systemMethod = class_getInstanceMethod(self, @selector(initWithFrame:));
Method customMethod = class_getInstanceMethod(self, @selector(m_initWithFrame:));
method_exchangeImplementations(systemMethod, customMethod);
}
- (instancetype)m_initWithFrame:(CGRect)frame {
UIScrollView *scrollV = [self m_initWithFrame:frame];
if (@available(iOS 11.0, *)) {
scrollV.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
return scrollV;
}
@end