Forráskód Böngészése

Merge pull request #1168 from itdongbaojun/master

修复MJRefresh中UIScrollView (MJExtension) 根据版本对执行代码的判断逻辑
M了个J 7 éve
szülő
commit
d0a924de91
1 módosított fájl, 15 hozzáadás és 10 törlés
  1. 15 10
      MJRefresh/UIScrollView+MJExtension.m

+ 15 - 10
MJRefresh/UIScrollView+MJExtension.m

@@ -15,17 +15,22 @@
 
 @implementation UIScrollView (MJExtension)
 
-static BOOL gt_ios_11_;
-+ (void)load
-{
-    // 缓存判断值
-    gt_ios_11_ = ([[[UIDevice currentDevice] systemVersion] compare:@"11" options:NSNumericSearch] != NSOrderedAscending);
+static BOOL mj_respondsToAdjustedContentInset;
+
+- (BOOL)gt_respondsToAdjustedContentInset {
+    
+    static dispatch_once_t onceToken;
+    dispatch_once(&onceToken, ^{
+        mj_respondsToAdjustedContentInset = [self respondsToSelector:@selector(adjustedContentInset)];
+    });
+    
+    return mj_respondsToAdjustedContentInset;
 }
 
 - (UIEdgeInsets)mj_inset
 {
 #ifdef __IPHONE_11_0
-    if (gt_ios_11_) {
+    if ([self gt_respondsToAdjustedContentInset]) {
         return self.adjustedContentInset;
     }
 #endif
@@ -37,7 +42,7 @@ - (void)setMj_insetT:(CGFloat)mj_insetT
     UIEdgeInsets inset = self.contentInset;
     inset.top = mj_insetT;
 #ifdef __IPHONE_11_0
-    if (gt_ios_11_) {
+    if ([self gt_respondsToAdjustedContentInset]) {
         inset.top -= (self.adjustedContentInset.top - self.contentInset.top);
     }
 #endif
@@ -54,7 +59,7 @@ - (void)setMj_insetB:(CGFloat)mj_insetB
     UIEdgeInsets inset = self.contentInset;
     inset.bottom = mj_insetB;
 #ifdef __IPHONE_11_0
-    if (gt_ios_11_) {
+    if ([self gt_respondsToAdjustedContentInset]) {
         inset.bottom -= (self.adjustedContentInset.bottom - self.contentInset.bottom);
     }
 #endif
@@ -71,7 +76,7 @@ - (void)setMj_insetL:(CGFloat)mj_insetL
     UIEdgeInsets inset = self.contentInset;
     inset.left = mj_insetL;
 #ifdef __IPHONE_11_0
-    if (gt_ios_11_) {
+    if ([self gt_respondsToAdjustedContentInset]) {
         inset.left -= (self.adjustedContentInset.left - self.contentInset.left);
     }
 #endif
@@ -88,7 +93,7 @@ - (void)setMj_insetR:(CGFloat)mj_insetR
     UIEdgeInsets inset = self.contentInset;
     inset.right = mj_insetR;
 #ifdef __IPHONE_11_0
-    if (gt_ios_11_) {
+    if ([self gt_respondsToAdjustedContentInset]) {
         inset.right -= (self.adjustedContentInset.right - self.contentInset.right);
     }
 #endif