我正在试图从我的UIViewController
的可见边界以外的一个按钮动画到它的中心。我的故事板中有一个约束设置,名为myButtonLeading
,我将其作为动画的一部分删除,然后我想添加一个名为newCenterConstraint
的新约束。为什么我无法在我的视图上安装约束?
@IBAction func updateDidTouch(_ sender: Any) {
UIView.animate(withDuration: 0.5, delay: 0, options: UIViewAnimationOptions.curveEaseInOut, animations: {
let newCenterConstraint = NSLayoutConstraint(item: self.myButton, attribute: .centerX, relatedBy: .equal, toItem: view, attribute: .centerX, multiplier: 1.0, constant: 0.0)
self.myButton.removeConstraint(self.myButtonLeading)
self.myButton.addConstraint(newCenterConstraint)
self.view.layoutIfNeeded()
}, completion: nil)
}
我已经把现在是给我关于我自己参考toItem: view
以下错误消息的代码。
在闭包中隐式使用'self';使用'自我'。使捕获 语义明确
但是,当我用我的self.view
应用程序崩溃与错误消息说:
无法在视图安装约束。该约束是否参考 来自视图子树之外的东西?这是违法的。
我在哪里错在这里添加新的centerX约束?
是按钮的上海华以self.view有关? – CZ54