Masonry 原理與使用說明

原理:佈局

1)約束生成;MASConstraintMaker;it

2)缺省補齊:class

- (void)setSecondViewAttribute:(id)secondViewAttribute {原理

    if ([secondViewAttribute isKindOfClass:NSValue.class]) {layout

        [self setLayoutConstantWithValue:secondViewAttribute];數據

    } else if ([secondViewAttribute isKindOfClass:MAS_VIEW.class]) {view

        _secondViewAttribute = [[MASViewAttribute alloc] initWithView:secondViewAttribute layoutAttribute:self.firstViewAttribute.layoutAttribute];vi

    } else if ([secondViewAttribute isKindOfClass:MASViewAttribute.class]) {ant

        _secondViewAttribute = secondViewAttribute;sse

    } else {

        NSAssert(NO, @"attempting to add unsupported attribute: %@", secondViewAttribute);

    }

}

3)尋找約束添加視圖,並添加

    if (self.secondViewAttribute.view) {

        MAS_VIEW *closestCommonSuperview = [self.firstViewAttribute.view mas_closestCommonSuperview:self.secondViewAttribute.view];

        NSAssert(closestCommonSuperview,

                 @"couldn't find a common superview for %@ and %@",

                 self.firstViewAttribute.view, self.secondViewAttribute.view);

        self.installedView = closestCommonSuperview;

    } else if (self.firstViewAttribute.isSizeAttribute) {

        self.installedView = self.firstViewAttribute.view;

    } else {

        self.installedView = self.firstViewAttribute.view.superview;

    }

4)

(1)絕對尺寸信息添加到自身;

(2)絕對佈局數據添加到父視圖;

(3)參考系屬性缺失補全爲目標屬性。

相關文章
相關標籤/搜索