【发布时间】:2011-10-27 15:42:20
【问题描述】:
我有一个父 UIView,它有子 UIView(在下面的代码中使用 UILabel),其框架设置为父的边界,其 autoresizingMask 设置为灵活的宽度和高度:
UIView* parentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
UILabel* childLabel = [[UILabel alloc] initWithFrame:parentView.bounds];
childLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
childLabel.textAlignment = UITextAlignmentCenter;
childLabel.text = @"Hello";
我希望能够为父视图的框架设置动画,特别是它的大小,并让子视图调整大小作为动画的一部分:
[UIView animateWithDuration:1.0 animations:^{ parentView.frame = CGRectMake(0, 0, 160, 240); }];
作为这个动画的结果,我希望 UILabel 的文本与父视图的动画一起动画,所以在视觉上你会看到文本从 (160, 240) 的中心移动到 (80, 120) .但是,子视图的帧似乎并没有动画化,而是立即设置为动画结束时应具有的值,因此您会看到动画开始时文本的位置立即跳转。
有没有办法让子视图作为动画的一部分自动调整大小?
【问题讨论】:
标签: ios cocoa-touch core-animation