3D仿射變換動畫類型同二維2D仿射變換動畫一樣有旋轉平移縮放
CATransform3DMakeScale(0.5, 0.5, 1.0);? //x,y,z放大縮小倍數(shù)
CATransform3DMakeRotation(1.57, 1, 1, 0); //1.57表示所轉角的弧度 = 90Pi/180 = 90*3.14/180
CATransform3DMakeTranslation(0, 0, 0); //位置移動
目的:在tableViewCell對象即將出現(xiàn)時添加動畫效果,tableview代理方法如下:
//添加每個cell出現(xiàn)時的3D動畫
(方法一)
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
//*************************************獲取變換對象*******************
//Transform3D對應4階矩陣
CATransform3D rotation;//定義3D旋轉對象
rotation = CATransform3DMakeRotation( (90.0*M_PI)/180, 0.0, 0.7, 0.4);//3D旋轉對象初始化//角度控制
//逆時針旋轉
rotation.m34 = 1.0/ -600;//4階矩陣的第3行第4列更改
//*************************************獲取變換對象*******************
cell.layer.shadowColor = [[UIColor blackColor]CGColor];
cell.layer.shadowOffset = CGSizeMake(10, 10);
cell.alpha = 0;
cell.layer.transform = rotation;//*****關鍵點****
//啟動旋轉動畫
[UIView beginAnimations:@"rotation" context:NULL];
//旋轉時間
[UIView setAnimationDuration:0.8];
//恢復原狀
cell.layer.transform = CATransform3DIdentity;
cell.alpha = 1;
cell.layer.shadowOffset = CGSizeMake(0, 0);
[UIView commitAnimations];
}
(方法二)
//添加每個cell出現(xiàn)時的3D動畫
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
CATransform3D rotation;//定義3D旋轉對象
rotation = CATransform3DMakeRotation( (90.0*M_PI)/180, 0.0, 0.7, 0.4);
rotation.m34 = 1.0/ -600;
cell.contentView.layer.transform = rotation;
cell.contentView.layer.anchorPoint=CGPointMake(0, 3);//旋轉錨點
[UIView animateWithDuration:0.8 animations:^{//先啟動前一個動畫,待結束后再啟動動畫模塊中的動畫指令
cell.contentView.layer.transform =CATransform3DIdentity;
cell.alpha=1;
}];
}
