
目标:
为单元格高度的变化设置动画并重新定位周围的单元格.
场景:
集合视图中的某些单元格会加载远程图像.最初,这些单元格的大小是静态的,并显示了活动指示符.加载图像后,将其添加到其单元格中,并更改单元格的高度以适合照片.
笔记:
我用它来动画细胞的框架变化animateWithDuration.这样可以正常工作,除了增加的单元尺寸使其与下面的单元重叠.collectionView.collectionViewLayout invalidateLayout在调整目标单元格大小并更新返回的大小后,我盲目地尝试调用但sizeForItemAtIndexPath没有成功.
有什么建议?谢谢!
示例代码:

objective-c uicollectionview uicollectionviewcell uicollectionviewlayout ios7
屏幕截图示例:

有什么更好的方法来动画调整包含子视图的UIView的大小?
我目前的方法:
在屏幕截图中,父UIView(橙色)有一个子视图UILabel(黄色+自动调整).animateWithDuration动画调整父UIView框架的大小.此方法的问题是它没有为子视图的大小调整设置动画.它突然改变,它应该动画缩放.
是否最明确地为子视图设置动画,还是有更有效的方法?(例如CGAffineTransform?)
示例代码:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.parentView = [[UIView alloc] initWithFrame:CGRectMake(10, 100, 200, 200)];
self.parentView.backgroundColor = [UIColor orangeColor];
[self.view addSubview:self.parentView];
self.childLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 180, 180)];
self.childLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight;
self.childLabel.backgroundColor = [UIColor yellowColor];
[self.parentView addSubview:self.childLabel];
[NSTimer scheduledTimerWithTimeInterval:2
target:self
selector:@selector(randomizeParentViewSize)
userInfo:nil
repeats:YES];
}
- (void)randomizeParentViewSize {
CGFloat width = arc4random_uniform(100) + 50;
CGFloat height = arc4random_uniform(100) + 50;
[UIView animateWithDuration:1.5f
delay:0.0f …Run Code Online (Sandbox Code Playgroud)