Reputation: 38005
Is it possible to animate a view from one frame to another by completely changing its constraints? I don't mean changing the properties of constraints, I know that works, but if I remove and re-add completely different constraints, can Auto Layout (or whatever subsystem it actually is… Core Animation?) animate the previous frame to the new frame, or does it need to keep the same instance of a constraint in order to animate it?
Upvotes: 1
Views: 170
Reputation: 11
If auto layout is in place (this is a default setting in Xcode), the best way to animate a view frame is changing the constraint constant
property and then ask Core Animation to animate the change. This is explained here: https://www.invasivecode.com/weblog/uikit-dynamics-layer-constraint/
If you try disabling the constraints and animating the view frame
, you will get a very weird behavior.
Just a note: starting from iOS 9, you should not remove or add the constraints. Instead, you have to activate and deactivate them, using the active
property. Apple changed this to improve the layout performance.
Upvotes: 1
Reputation: 1640
That would be an interesting thing to explore. In theory, you could remove all constraints from a view. UiView offers the appropriate functions for that.
You would then need to add a new set of constraints in the same scope preferably. Then call layoutifneeded (in an animation block) and then post your results.
Good luck
Upvotes: 0