美文网首页
iOS 11 适配 简单粗暴

iOS 11 适配 简单粗暴

作者: lyking | 来源:发表于2017-09-21 15:40 被阅读97次

    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
    

    相关文章

      网友评论

          本文标题:iOS 11 适配 简单粗暴

          本文链接:https://www.haomeiwen.com/subject/fwzzsxtx.html