UITableView是iOS APP開(kāi)發(fā)過(guò)程中最常使用的一個(gè)組件了涎嚼,給UITableViewCell的加載添加一些動(dòng)畫可以讓界面的用戶體驗(yàn)更好,下面就介紹幾種常用的加載動(dòng)畫猩系。
以下動(dòng)畫只要在tableview的以下代理方法調(diào)用相應(yīng)動(dòng)畫方法即可。
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
//[self leftInsertAnimation:cell];
//[self springAnimation_1:cell];
//[self springAnimation_2:cell];
//[self left3DAnimation:cell];
[self flyInAnimation:cell];
}
1昧穿、左側(cè)插入動(dòng)畫
-(void) leftInsertAnimation:(UITableViewCell*)cell{
CGPoint center = cell.center;
CGPoint orgCenter = center;
center.x += cell.bounds.size.width;
cell.center = center;
[UIView animateWithDuration:0.5 animations:^{
cell.center = orgCenter;
}];
}
2凡壤、彈簧效果
-(void) springAnimation_1:(UITableViewCell*)cell{
CGPoint center = cell.center;
CGPoint orgCenter = center;
center.y += cell.bounds.size.height;
cell.center = center;
[UIView animateWithDuration:0.5 animations:^{
cell.center = orgCenter;
}];
}
3署尤、折疊展開(kāi)效果
-(void) springAnimation_2:(UITableViewCell*)cell{
cell.transform = CGAffineTransformMakeTranslation(0, -80);
[UIView animateWithDuration:0.5 animations:^{
cell.transform = CGAffineTransformIdentity;
}];
}
4耙替、左側(cè)3D變幻效果
-(void) left3DAnimation:(UITableViewCell*) cell{
CATransform3D rotation;
rotation = CATransform3DMakeRotation( (90.0*M_PI)/180, 0.0, 0.7, 0.4);
rotation.m34 = 1.0/ -600;
cell.layer.shadowColor = [[UIColor blackColor]CGColor];
cell.layer.shadowOffset = CGSizeMake(10, 10);
cell.alpha = 0;
cell.layer.transform = rotation;
cell.layer.anchorPoint = CGPointMake(0, 0.5);
[UIView beginAnimations:@"rotation" context:NULL];
[UIView setAnimationDuration:0.8];
cell.layer.transform = CATransform3DIdentity;
cell.alpha = 1;
cell.layer.shadowOffset = CGSizeMake(0, 0);
[UIView commitAnimations];
}
5、底部飛入效果
-(void) flyInAnimation:(UITableViewCell*) cell{
cell.layer.transform = CATransform3DMakeScale(0.1, 0.1, 1);
//x和y的最終值為1
[UIView animateWithDuration:1 animations:^{
cell.layer.transform = CATransform3DMakeScale(1, 1, 1);
}];
}
以上的動(dòng)畫在上拉和下拉時(shí)都有效曹体,要是想只在上滑或者下滑時(shí)有效俗扇,需要配合scrollView代理方法進(jìn)行使用:例如飛入效果,可以使用一個(gè)全局變量去設(shè)置箕别,cell.layer.transform的值铜幽。
-(void) scrollViewDidScroll:(UIScrollView *)scrollView{
if (scrollView.contentOffset.y < oldOffset) {//向上滾動(dòng)
self.transform3D = CATransform3DMakeScale(1, 1, 1);
}else if(scrollView.contentOffset.y > oldOffset){//向下
self.transform3D = CATransform3DMakeScale(0.1, 0.1, 1);
}
oldOffset = scrollView.contentOffset.y;
}
注
動(dòng)畫效果可以自定義