點擊上方「程式設計師共讀」,選擇「置頂公眾號」
關鍵時刻,第一時間送達!
正文
TableViewAnimationKit調用各個動畫的方法都為類方法,只需一行代碼就可以調用。
eg:
[TableViewAnimationKit shakeAnimationWithTableView:tableView];
TableViewAnimationKit提供的動畫類方法
+ (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;
先舉其中一個動畫效果為例子:
動畫效果為Cell左右各自插入。
實現代碼很簡單如下:
+ (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的執行時間、方向有所差異,一起構成整個動畫。
後語
源碼: https://github.com/alanwangmodify/TableViewAnimationKit
【點擊成為安卓大神】