UIView动画不工作在ios 5.1

问题描述:

我有一个UITableView。我想在单元格在表格中加载时制作动画。我是这样做的。UIView动画不工作在ios 5.1

-(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)。

+0

关注此链接buddy.http://*.com/questions/14727380/uitableview-of-ios-sdk-6-1-dont-compatible-with-ios-sdk-5-1/14727833#14727833 – Rajneesh071 2013-02-15 12:09:20

完成。 我把这段代码放入

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

return cell。

所以我知道你已经有解决方案,但我可能会推荐使用动画块,除非你使它与旧版本兼容。无论如何,如果你不是这可能会提供一种不同的方式来写动画。我喜欢这样做,因为我觉得我可以更好地控制发生的事情,减少混乱。

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 

       }]; 

太棒了!保重^^

编辑

去测试它,并意识到我离开了一个重要组成部分。我很抱歉..但是这段代码确实有效,并且会在分页的表格上完成这种动画。