我有这个约束的观点。我想为它设置动画并移动到 NavigationBar
的底部。所以我想将 Second item
属性更改为如下所示:
UIView.animateWithDuration(15.5, delay: 0.0, options: UIViewAnimationOptions.CurveEaseInOut, animations: {
if (self.isViewLoaded() && self.view.window != nil) {
//How to set bottom item ?
self.storeSelectViewVerticalContainerConstraint.secondItem = self.navigationController?.view.bottom
self.view.layoutIfNeeded()
}
}, completion: {(Bool) in})
此代码返回错误:
Cannot assign to property: 'secondItem' is a get-only property
或者如果这种方法不可行,如何计算并使用导航栏将对象从 View 中间移动到顶部。
最佳答案
您可以添加第二个优先级较低的约束来开始,然后在需要时更新两个优先级:
UIView.animateWithDuration(15.5, delay: 0.0, options: UIViewAnimationOptions.CurveEaseInOut, animations: {
if (self.isViewLoaded() && self.view.window != nil) {
self.storeSelectViewVerticalContainerConstraint.priority = UILayoutPriorityDefaultLow
self.storeSelectViewTopContainerConstraint.priority = UILayoutPriorityDefaultHigh
self.view.layoutIfNeeded()
}
}, completion: {(Bool) in})
记住不要将优先级从必需移动到不需要,因为 that's not allowed .但是从一个可选值移动到另一个可选值是可以的。
或者,您可以只删除/添加这些约束,而不是更改它们的优先级。
关于ios - 改变约束第二项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35479924/