objective-c - UITableViewRowAnimation 自定义动画

标签 objective-c ios cocoa-touch uitableview

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

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

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

最佳答案

一种方法是在 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。随着表格的滚动,单元格会缩小并变得不透明。你真的可以在这里做任何你想做的事。

关于objective-c - UITableViewRowAnimation 自定义动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11514997/

相关文章:

ios - 我如何比较两个 iOS 本地网络服务器?

ios - 如何在 iPhone 上使用 OpenGL ES 绘制实心圆?

ios - 核心数据和连接条件后的排序

iphone - 如何测试方法的协议(protocol)?

ios - UIButton 没有被实例化

ios - 使用条码角创建 CGRect?

ios - 计算 UITextView 所需的大小

ios - UILabel 在自定义 UItableviewcell 中显示(null)

java - 试图将 api 身份验证从 iOS 应用程序复制到 java 中,不要用户理解代码

iphone - 你能用 NSPredicate 指定 "select unique name from ..."吗?