iOS 11 适配 简单粗暴

2017-09-21  本文已影响97人  lyking

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
上一篇下一篇

猜你喜欢

热点阅读