首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >UIView动画在iOS5.1中不工作

UIView动画在iOS5.1中不工作
EN

Stack Overflow用户
提问于 2013-02-15 18:19:31
回答 2查看 515关注 0票数 1

我有一台UITableView。我想在表格中加载单元格时制作动画。我是这样做的。

代码语言:javascript
运行
复制
-(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)中不起作用。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-02-15 18:30:50

好了。我把这段代码放到

代码语言:javascript
运行
复制
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

在返回单元格之前。

票数 0
EN

Stack Overflow用户

发布于 2013-02-21 15:51:48

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

代码语言:javascript
运行
复制
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

                 }];

太棒了!小心^^

编辑

去测试它,发现我遗漏了一个重要的部分。我很抱歉..但是这段代码确实可以工作,并且可以做这个动画,这在一个包含很多部分的分组表上是很有趣的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14892537

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档