我有一台UITableView。我想在表格中加载单元格时制作动画。我是这样做的。
-(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
CGRect tmpFrame;
CGRect originalFrame;
originalFrame = cell.frame;
tmpFrame = cell.frame;
tmpFrame = CGRectMake(0, -50, 320, 50);
cell.frame = tmpFrame;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:5.0f];
[UIView setAnimationBeginsFromCurrentState:YES];
UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 50, 320, 1)];
separatorLineView.backgroundColor = [UIColor lightGrayColor];
[cell.contentView addSubview:separatorLineView];
cell.frame = originalFrame;
[UIView commitAnimations];
}此代码在iOS 6 (iPhone模拟器6)中运行良好,但在iOS 5.1 (iPhone模拟器5.1)中不起作用。
发布于 2013-02-15 18:30:50
好了。我把这段代码放到
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath在返回单元格之前。
发布于 2013-02-21 15:51:48
所以我知道你已经有了解决方案,但我可能会推荐使用动画块,除非你想让它与旧版本兼容。无论如何,如果你不是,这可能会提供一种不同的方式来编写动画。我喜欢这样做,因为我觉得我对发生的事情有更多的控制,更少的混乱。
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if(!cell){
cell = [[UITableViewCell alloc]init];
}
CGRect movementFrame = cell.frame; // set the movement frame for modification
movementFrame.origin.y -= 50; //adjust only one variable instead of making a rect..
//Start your animation block.
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationCurveEaseOut
animations:^{
//Animation here
cell.frame = movementFrame; // Commit your changes basically
} completion:^(BOOL finished) {
//Completeion c
}];太棒了!小心^^
编辑
去测试它,发现我遗漏了一个重要的部分。我很抱歉..但是这段代码确实可以工作,并且可以做这个动画,这在一个包含很多部分的分组表上是很有趣的。
https://stackoverflow.com/questions/14892537
复制相似问题