I'm facing an issue. I'm working on an app and I'm using storyboard
with Autolayout enabled. Now on one of my UIViewControllers
I have placed a UIView
(say A). Now A has multiple subviews (UIViews
to be precise). I have applied the "Horizontally and Vertically centered
" constraint on A. The subviews inside A don't have any constraints on them.
Now in my code I have a method for animating the subviews that are inside A. Inside that method I call the UIView's
animation method...
[UIView animateWithDuration: delay: options: animations: completion:];
and animate one of the subview's inside View A. Now the problem is that these frame changes don't persist. When I modal a view controller on current view controller and then dismiss it the frames of all the subviews inside A get reset.
I searched for it and found out the problem is occuring because of Autolayout. I disabled it and then tried again and everything worked well.
But what is the workaround with Autolayout enabled...?
Am I missing something...?
The interesting thing is that many posts on StackOverflow suggested that
we should animate the constraints and NOT the frames when using autolayout.
BUT I haven't applied any constraints on the subviews that are inside View A. Constraints are only applied on View A.
Thanks.
For all the views that you are animating write the following code in viewDidLoad
myViewToAnimate.translatesAutoresizingMaskIntoConstraints = YES;
Hope this helps
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