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級別,後面會繼續優化、增長動畫。若有什麼想法,歡迎進行技術交流。優化