-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconstraint.js
More file actions
88 lines (76 loc) · 3.99 KB
/
constraint.js
File metadata and controls
88 lines (76 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
exports.Constraint = function(id_lu, plistCenter) {
this.id_lu = id_lu
this.plistCenter = plistCenter
this.firstItemName = plistCenter.getConstraintItemNameOf(id_lu, true)
this.secondItemName = plistCenter.getConstraintItemNameOf(id_lu, false)//如果是width/height固定值就不会有second item
this.firstAttribute = plistCenter.getConstraintAttriOf(id_lu, true)
this.secondAttribute = plistCenter.getConstraintAttriOf(id_lu, false)
this.constant = plistCenter.getConstraintContantOf(id_lu)
this.multiplier = plistCenter.getConstraintMultiplierOf(id_lu)
//还要支持priority、relation
var description
if (typeof (this.firstItemName) != "undefined") {
if (typeof (this.secondItemName) != "undefined") {
var des = this.firstItemName + '.' + this.firstAttribute + "Anchor.constraint(equalTo:" + this.secondItemName + "." + this.secondAttribute + "Anchor"
if (typeof (this.constant) == "undefined" || this.constant == '0') {
des = des + ")"
} else {
des = des + ", constant: " + this.constant + ")"
}
des = des + ".isActive = true"
} else {
//检查是不是width/height恒等
if ((this.firstAttribute == "width" || this.firstAttribute == "height") && (typeof (this.constant) != "undefined") && this.constant != '0') {
//equalToConstant
var des = this.firstItemName + '.' + this.firstAttribute + "Anchor.constraint(equalToConstant: " + this.constant + ")"
des = des + ".isActive = true"
} else {
description = description + "第二个对象处理方式未知 constraint ID:" + this.id_lu
}
}
description = des
}
if (typeof (this.firstItemName) == undefined) {
description = description + "未取到first item constraint ID:" + this.id_lu
}
this.description = description
this.descriptionOfID = function (itemID) {
if (this.controller.viewDic.hasOwnProperty(itemID) == false) {
//看看是不是contentview模式引起的
let secondItemKey = this.$("#" + itemID).attr("key")
if (typeof (secondItemKey) == "undefined") {
if (this.$("#" + itemID)[0].tagName == "VIEWCONTROLLERLAYOUTGUIDE") {
//特殊模式,controller的layoutguide
let layoutGuide = this.$("#" + itemID).parent()
let guideType = this.$(layoutGuide).attr("type")
return "view.layoutMarginsGuide"
} else {
console.log("constraint特殊情况,secondItem未被收录 寻找的ID:" + itemID)
}
} else {
//contentview模式处理
//contentview模式指在storyboard中发现的一种模式:有的view标签中有一个key属性,这往往代表着这个view没有在明面上出现,是以另一个view/controller的属性
//tableViewCell
var containViewID
let containViewList = ["tableViewCell"]
for (let index = 0; index < containViewList.length; index++) {
const containViewName = containViewList[index];
let containViewID1 = this.$("#" + itemID).attr(containViewName)
if (typeof (containViewID1) == "undefined") {
} else {
containViewID = containViewID1
break
}
}
if (typeof (containViewID) == "undefined") {
console.log("constraint寻找secondItem contentview模式 没找到容器view")
} else {
let desOfContainView = this.descriptionOfID(containViewID)
return desOfContainView + "." + secondItemKey
}
}
} else {
return this.controller.viewDic[itemID].name()
}
}
}