Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS animating a view including subviews

I'm trying to make an animation for collapsing a view which includes some subviews.

[UIView beginAnimations:@"advancedAnimations" context:nil];
[UIView setAnimationDuration:3.0];

CGRect aFrame = aView.frame;
aView.size.height = 0;
aView.frame = aFrame;

[UIView commitAnimations];

This animation is doing fine, but for the aView only. Subviews doesn't collapse as expected. How do I make the subviews collapsing as well? Furthermore, is there a way to recalculate original size after collapsing?

THX

like image 660
toppless Avatar asked May 15 '12 15:05

toppless


2 Answers

You have probably forgotten to apply some autoresizing mask to your subviews. If you do

for (UIView *subview in aView.subviews) {
    subview.autoresizingMask = (UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin);
}

it should work.

BUT, personally I would use, as lamelas said

aView.transform = CGAffineTransformMakeScale(1.0,0.0);
like image 160
Zoleas Avatar answered Sep 22 '22 10:09

Zoleas


Try using this to animate:

aView.transform = CGAffineTransformMakeScale(1.0,0.0);
like image 41
lamelas Avatar answered Sep 18 '22 10:09

lamelas