将NSLayoutConstraint说明为框架

时间:2018-11-20 08:12:17

标签: ios swift autolayout nslayoutconstraint

我想通过JSON字符串从服务器获取我的图层布局信息。并且布局信息与NSLayoutConstraint的结构相同。

[
    {
        "secondItem": "1", // id of second item, can be use to find the related layer, the first item is a existed layer
        "firstAttribute": "left", // same as NSLayoutConstraint.Attribute
        "secondAttribute": "left",
        "relation": "equal",    // same as NSLayoutRelation
        "multiplier": "1",
        "constant": "10"
    },

    {
        "secondItem": "1",
        "firstAttribute": "right",
        "secondAttribute": "right",
        "relation": "equal",
        "multiplier": "1",
        "constant": "10"
    },

    {
        "secondItem": "1", 
        "firstAttribute": "top",
        "secondAttribute": "top",
        "relation": "equal",
        "multiplier": "1",
        "constant": "10"
    },

    {
        "secondItem": "1",
        "firstAttribute": "bottom",
        "secondAttribute": "bottom",
        "relation": "equal",
        "multiplier": "1",
        "constant": "10"
    }
]

这些JSON仅用于描述CALayer的布局信息,而不是直接应用于UIView

但是如何说明NSLayoutConstraintCALayer的边界和位置属性?

谢谢!

0 个答案:

没有答案