改变约束第二项

Change constraint second item

我对这个限制有看法。我想为它设置动画并移动到 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})

此代码returns错误:

Cannot assign to property: 'secondItem' is a get-only property

或者如果这种方法不可行,如何计算,并使用导航栏将对象从视图中间移动到顶部。

您可以添加第二个优先级较低的约束来启动,然后在需要时更新两个优先级:

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。但是从一个可选值移动到另一个可选值是可以的。

或者,您可以 remove/add 这些约束而不是更改它们的优先级。

这里第二项是UIView(Main Root View),也就是Y Axis Fixed。无法更改。

如果您想要商店选择视图的动画,您应该将其常量从一个值更改为另一个值,然后执行

storeSelectViewVerticalContainerConstraint.constant = 0; // or any value you want.
UIView.animateWithDuration(5) {
    self.view.layoutIfNeeded()
}

谢谢。 编码愉快!