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.
Select the height constraint from the Interface builder and take an outlet of it. So, when you want to change the height of the view you can use the below code. Method updateConstraints() is an instance method of UIView . It is helpful when you are setting the constraints programmatically.
Since multiplier is a read-only property and you can't change it, you need to replace the constraint with its modified clone.
addConstraint(constY); var constW:NSLayoutConstraint = NSLayoutConstraint(item: new_view, attribute: NSLayoutAttribute. Width, relatedBy: NSLayoutRelation. Equal, toItem: new_view, attribute: NSLayoutAttribute. Width, multiplier: 1, constant: 0); self.
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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With