ソースを参照

support safeAreaLayoutGuide

iwill 8 年 前
コミット
2cf22518e8
3 ファイル変更72 行追加6 行削除
  1. 6 1
      Masonry/MASViewConstraint.m
  2. 18 5
      Masonry/View+MASAdditions.h
  3. 48 0
      Masonry/View+MASAdditions.m

+ 6 - 1
Masonry/MASViewConstraint.m

@@ -125,7 +125,12 @@ static char kInstalledConstraintsKey;
     } else if ([secondViewAttribute isKindOfClass:MAS_VIEW.class]) {
         _secondViewAttribute = [[MASViewAttribute alloc] initWithView:secondViewAttribute layoutAttribute:self.firstViewAttribute.layoutAttribute];
     } else if ([secondViewAttribute isKindOfClass:MASViewAttribute.class]) {
-        _secondViewAttribute = secondViewAttribute;
+        MASViewAttribute *attr = secondViewAttribute;
+        if (attr.layoutAttribute == NSLayoutAttributeNotAnAttribute) {
+            _secondViewAttribute = [[MASViewAttribute alloc] initWithView:attr.view item:attr.item layoutAttribute:self.firstViewAttribute.layoutAttribute];;
+        } else {
+            _secondViewAttribute = secondViewAttribute;
+        }
     } else {
         NSAssert(NO, @"attempting to add unsupported attribute: %@", secondViewAttribute);
     }

+ 18 - 5
Masonry/View+MASAdditions.h

@@ -54,11 +54,24 @@
 
 #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 110000) || (__TV_OS_VERSION_MIN_REQUIRED >= 110000)
 
-@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuide;
-@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideTop;
-@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideBottom;
-@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideLeft;
-@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideRight;
+@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeArea;
+
+@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLeading;
+@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaTrailing;
+@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLeft;
+@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaRight;
+@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaTop;
+@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaBottom;
+@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaWidth;
+@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaHeight;
+@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaCenterX;
+@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaCenterY;
+
+@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuide DEPRECATED_ATTRIBUTE;
+@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideTop DEPRECATED_ATTRIBUTE;
+@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideBottom DEPRECATED_ATTRIBUTE;
+@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideLeft DEPRECATED_ATTRIBUTE;
+@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideRight DEPRECATED_ATTRIBUTE;
 
 #endif
 

+ 48 - 0
Masonry/View+MASAdditions.m

@@ -136,6 +136,54 @@
 
 #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 110000) || (__TV_OS_VERSION_MIN_REQUIRED >= 110000)
 
+#pragma mark - safeAreaLayoutGuide
+
+- (MASViewAttribute *)mas_safeArea {
+    return [[MASViewAttribute alloc] initWithView:self item:self.safeAreaLayoutGuide layoutAttribute:NSLayoutAttributeNotAnAttribute];
+}
+
+- (MASViewAttribute *)mas_safeAreaLeading {
+    return [[MASViewAttribute alloc] initWithView:self item:self.safeAreaLayoutGuide layoutAttribute:NSLayoutAttributeLeading];
+}
+
+- (MASViewAttribute *)mas_safeAreaTrailing {
+    return [[MASViewAttribute alloc] initWithView:self item:self.safeAreaLayoutGuide layoutAttribute:NSLayoutAttributeTrailing];
+}
+
+- (MASViewAttribute *)mas_safeAreaLeft {
+    return [[MASViewAttribute alloc] initWithView:self item:self.safeAreaLayoutGuide layoutAttribute:NSLayoutAttributeLeft];
+}
+
+- (MASViewAttribute *)mas_safeAreaRight {
+    return [[MASViewAttribute alloc] initWithView:self item:self.safeAreaLayoutGuide layoutAttribute:NSLayoutAttributeRight];
+}
+
+- (MASViewAttribute *)mas_safeAreaTop {
+    return [[MASViewAttribute alloc] initWithView:self item:self.safeAreaLayoutGuide layoutAttribute:NSLayoutAttributeTop];
+}
+
+- (MASViewAttribute *)mas_safeAreaBottom {
+    return [[MASViewAttribute alloc] initWithView:self item:self.safeAreaLayoutGuide layoutAttribute:NSLayoutAttributeBottom];
+}
+
+- (MASViewAttribute *)mas_safeAreaWidth {
+    return [[MASViewAttribute alloc] initWithView:self item:self.safeAreaLayoutGuide layoutAttribute:NSLayoutAttributeWidth];
+}
+
+- (MASViewAttribute *)mas_safeAreaHeight {
+    return [[MASViewAttribute alloc] initWithView:self item:self.safeAreaLayoutGuide layoutAttribute:NSLayoutAttributeHeight];
+}
+
+- (MASViewAttribute *)mas_safeAreaCenterX {
+    return [[MASViewAttribute alloc] initWithView:self item:self.safeAreaLayoutGuide layoutAttribute:NSLayoutAttributeCenterX];
+}
+
+- (MASViewAttribute *)mas_safeAreaCenterY {
+    return [[MASViewAttribute alloc] initWithView:self item:self.safeAreaLayoutGuide layoutAttribute:NSLayoutAttributeCenterY];
+}
+
+#pragma mark - DEPRECATED
+
 - (MASViewAttribute *)mas_safeAreaLayoutGuide {
     return [[MASViewAttribute alloc] initWithView:self item:self.safeAreaLayoutGuide layoutAttribute:NSLayoutAttributeBottom];
 }