最近感觉好多人还在问如何判断iOS11系统的问题,以为过了这么多大家都适配好了,其实不然。
为什么要搞一个宏定义呢,因为有些小伙伴Xcode版本还是停留在Xcode8,这样判断是iOS11的方法就尴尬了,所以搞个宏。
//----------------------------------- iOS11适配 ------------------------------------
#define adjustsScrollViewInsets(scrollView)\
do {\
_Pragma("clang diagnostic push")\
_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"")\
if ([scrollView respondsToSelector:NSSelectorFromString(@"setContentInsetAdjustmentBehavior:")]) {\
NSMethodSignature *signature = [UIScrollView instanceMethodSignatureForSelector:@selector(setContentInsetAdjustmentBehavior:)];\
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];\
NSInteger argument = 2;\
invocation.target = scrollView;\
invocation.selector = @selector(setContentInsetAdjustmentBehavior:);\
[invocation setArgument:&argument atIndex:2];\
[invocation retainArguments];\
[invocation invoke];\
}\
_Pragma("clang diagnostic pop")\
} while (0)
在需要使用的地方写上:
adjustsScrollViewInsets(<#scrollView#>)
即可。
网友评论