Reputation: 7762
I have a view with this constraint. I want to animate it and move to bottom of NavigationBar
. So i want to change Second item
attribute to something like this:
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})
This code returns error:
Cannot assign to property: 'secondItem' is a get-only property
Or if this method is impossible, how to calculate, and move object from middle to top of view with navigation bar.
Upvotes: 12
Views: 9114
Reputation: 2600
You could add a second constraint with lower priority to start and then update both priorities when you need to:
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})
Remember to not move the priority from required to not required though, since that's not allowed. But moving from an optional value to another optional value is ok.
Alternatively you could just remove/add these constraints instead of changing their priority.
Upvotes: 28
Reputation: 15639
Here Second Item is UIView(Main Root View), which is Y Axis Fixed. It can't be altered.
If you want animation of store selection view, you should change its constant from one value to another, and do
storeSelectViewVerticalContainerConstraint.constant = 0; // or any value you want.
UIView.animateWithDuration(5) {
self.view.layoutIfNeeded()
}
Thanks. Happy Coding!
Upvotes: 2