约束条件下的Swift错误

时间:2015-01-08 21:39:19

标签: swift ios8

我试图为使用UIPanGestureRecognizer移动的按钮创建一些约束

button.setTranslatesAutoresizingMaskIntoConstraints(false)

let line = ("\(p.x % snapX)")
let column = ("\(p.x % snapY)")

let constraint2 = NSLayoutConstraint(item: button, attribute: .CenterX, relatedBy: .Equal, toItem: view, attribute: .CenterX, multiplier: 1, constant: CGFloat(line))

let constraint3 = NSLayoutConstraint(item: button, attribute: .CenterY, relatedBy: .Equal, toItem: view, attribute: .CenterY, multiplier: 1, constant: CGFloat(column))

view.addConstraints([constraint2,constraint3])

但我有一个"找不到会员' CenterX'错误

P.S。行和列可以采用例如值27.6666564941406和0.666656494140625

1 个答案:

答案 0 :(得分:0)

看起来编译器试图在错误的枚举类型上找到CenterX。尝试使用完整的枚举定义:

NSLayoutAttribute.CenterX

NSLayoutAttribute.CenterY