我知道有默认的 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/