ios - 改变约束第二项

标签 ios swift constraints

enter image description here

我有这个约束的观点。我想为它设置动画并移动到 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/

相关文章:

iphone - UIImageView 动画慢

ios - 不知何故结合搜索 Controller 不起作用,知道吗?

iOS:设置 Storyboard后编辑 View 的约束

swift - 如何在 SwiftUI 中访问父框架

codeigniter - NSURLSession iOS CodeIgniter 不发送 POST

iOS 自动布局约束在 View 加载后跳转

ios - 通过第三方应用程序播放苹果音乐歌曲

ios - 如何在相同的 "didSelectRowAtIndexPath"方法中再次调用 "didSelectRowAtIndexPath"方法

ios - 导航栏在 iPhone 4 (iOS 7.1.2) 中消失

swift - 根据旋转向前移动 3d 模型