最近感覺好多人還在問如何判斷iOS11系統(tǒng)的問題,以為過了這么多大家都適配好了,其實不然。
為什么要搞一個宏定義呢,因為有些小伙伴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#>)
即可。