前言
UITableView 是iOS日常開發(fā)中經(jīng)常使用到的控件。tableView的普通展示效果比較生硬井赌,為了提升APP的活力伶椿,提升體驗(yàn),我們可以對(duì)根據(jù)tableView的特點(diǎn)菊霜,操作Cell實(shí)現(xiàn)一些動(dòng)畫效果坚冀。
我寫了一個(gè)簡單的動(dòng)畫集 TableViewAnimationKit,只需要一行代碼就可以讓tableView實(shí)現(xiàn)動(dòng)畫
目前有大概10個(gè)動(dòng)畫鉴逞,后續(xù)會(huì)優(yōu)化增加记某。
源碼放到Github上: TableViewAnimationKit歡迎大家star、下載华蜒,交流溝通辙纬。
正文
一、效果展示:
二叭喜、使用方法
TableViewAnimationKit調(diào)用各個(gè)動(dòng)畫的方法都為類方法贺拣,只需一行代碼就可以調(diào)用。
eg:
[TableViewAnimationKit shakeAnimationWithTableView:tableView];
TableViewAnimationKit提供的動(dòng)畫類方法
+ (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;
三捂蕴、源碼講解
先舉其中一個(gè)動(dòng)畫效果為例子:
動(dòng)畫效果為Cell左右各自插入譬涡。
實(shí)現(xiàn)代碼很簡單如下:
+ (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
數(shù)組,進(jìn)行遍歷啥辨,對(duì)每個(gè)執(zhí)行動(dòng)畫涡匀,不同cell的執(zhí)行時(shí)間、方向有所差異溉知,一起構(gòu)成整個(gè)動(dòng)畫陨瘩。
四、其他一些動(dòng)畫效果
后語
源碼放到Github上: TableViewAnimationKit有需要的同學(xué)可以下載级乍、star舌劳,目前只算Demo級(jí)別,后面會(huì)繼續(xù)優(yōu)化玫荣、增加動(dòng)畫甚淡。如有什么想法,歡迎進(jìn)行技術(shù)交流捅厂。