UITableView 是iOS平常开发中常常使用到的控件。tableView的普通展现效果比较生硬,为了提高APP的活力,提高体验,咱们能够对根据tableView的特色,操做Cell实现一些动画效果。
我写了一个简单的动画集 TableViewAnimationKit,只须要一行代码就可让tableView实现动画
目前有大概10个动画,后续会优化增长。
源码放到Github上: TableViewAnimationKit欢迎你们star、下载,交流沟通。git
TableViewAnimationKit调用各个动画的方法都为类方法,只需一行代码就能够调用。
eg:github
[TableViewAnimationKit shakeAnimationWithTableView:tableView];复制代码
TableViewAnimationKit提供的动画类方法spring
+ (void)moveAnimationWithTableView:(UITableView *)tableView;
+ (void)alphaAnimationWithTableView:(UITableView *)tableView;
+ (void)fallAnimationWithTableView:(UITableView *)tableView;
+ (void)shakeAnimationWithTableView:(UITableView *)tableView;
+ (void)overTurnAnimationWithTableView:(UITableView *)tableView;
+ (void)toTopAnimationWithTableView:(UITableView *)tableView;
+ (void)springListAnimationWithTableView:(UITableView *)tableView;
+ (void)shrinkToTopAnimationWithTableView:(UITableView *)tableView;
+ (void)layDonwAnimationWithTableView:(UITableView *)tableView;
+ (void)roteAnimationWithTableView:(UITableView *)tableView;复制代码
先举其中一个动画效果为例子:
数组
+ (void)shakeAnimationWithTableView:(UITableView *)tableView {
NSArray *cells = tableView.visibleCells;
for (int i = 0; i < cells.count; i++) {
UITableViewCell *cell = [cells objectAtIndex:i];
if (i%2 == 0) {
cell.transform = CGAffineTransformMakeTranslation(-XS_SCREEN_WIDTH,0);
}else {
cell.transform = CGAffineTransformMakeTranslation(XS_SCREEN_WIDTH,0);
}
[UIView animateWithDuration:0.4 delay:i*0.03 usingSpringWithDamping:0.75 initialSpringVelocity:1/0.75 options:0 animations:^{
cell.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished) {
}];
}
}复制代码
主要思路为:
得到tableview的visibleCells
数组,进行遍历,对每一个执行动画,不一样cell的执行时间、方向有所差别,一块儿构成整个动画。bash
源码放到Github上: TableViewAnimationKit有须要的同窗能够下载、star,目前只算Demo级别,后面会继续优化、增长动画。若有什么想法,欢迎进行技术交流。优化