【问题标题】:UITableViewRowAnimation custom animationUITableViewRowAnimation 自定义动画
【发布时间】:2012-07-17 01:47:04
【问题描述】:

我知道有默认的UITableViewRowAnimation 选项,但是有没有办法创建我自己的动画?如果是这样,他们的教程是关于这个的吗?

我希望我的单元格向用户缩放,然后飞出屏幕。

我似乎找不到太多关于这个的信息......

【问题讨论】:

  • 可能重复:stackoverflow.com/questions/11382936/…>
  • 可能是重复的,但仍然需要找到答案。

标签: objective-c ios cocoa-touch uitableview


【解决方案1】:

一种方法是在 willDisplayCell 中,您可以在那里访问 UIView/CAAnimation API。示例:

- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{   
    //1. Define the initial state (Before the animation)
    cell.layer.shadowColor = [[UIColor blackColor]CGColor];
    cell.layer.shadowOffset = CGSizeMake(10, 10);
    cell.alpha = 0;
    cell.transform = CGAffineTransformMakeScale(0.85, 0.85);

    //2. Define the final state (After the animation) and commit the animation
    [UIView beginAnimations:@"scale" context:NULL];
    [UIView setAnimationDuration:0.5];
    cell.transform = CGAffineTransformIdentity;
    cell.alpha = 1;
    cell.layer.shadowOffset = CGSizeMake(0, 0);
    [UIView commitAnimations];
}

这是应用于单元格的简单“缩放”、阴影和 alpha-in。随着表格的滚动,单元格会缩小并变得不透明。你真的可以在这里做任何你想做的事情。

【讨论】:

    猜你喜欢
    • 2016-06-15
    • 1970-01-01
    • 2012-06-02
    • 2012-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多