iOS动画包含子视图的视图

时间:2012-05-15 15:33:13

标签: ios xcode animation uiview

我正在尝试制作动画来折叠包含一些子视图的视图。

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

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

[UIView commitAnimations];

这个动画很好,但仅适用于aView。子视图不会按预期崩溃。 如何使子视图也崩溃?此外,有没有办法在折叠后重新计算原始大小?

THX

3 个答案:

答案 0 :(得分:5)

您可能忘记在子视图中应用一些自动调整遮罩。如果你这样做

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

它应该有用。

,但 就像拉梅拉斯所说的那样,我会亲自使用

aView.transform = CGAffineTransformMakeScale(1.0,0.0);

答案 1 :(得分:4)

尝试使用它来制作动画:

aView.transform = CGAffineTransformMakeScale(1.0,0.0);

答案 2 :(得分:0)

一个有根据的猜测:

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

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

for (UIView *subview in aView.subviews) {
    CGRect frame = subview.frame;
    frame.size.height = 0;
    subview.frame = frame;
}

[UIView commitAnimations];
  

此外,有没有办法在折叠后重新计算原始尺寸?

你可能只想在折叠前保存高度。

相关问题