tableView 中一些動畫效果一般都是實現willDisplayCell的方法來展現出一些動畫的效果動畫
(1).帶有3D效果的小型動態展現spa
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{3d
CATransform3D rotation;orm
rotation = CATransform3DMakeRotation( (-48.0*M_PI)/180, 0.0, 0.7, 0.4);animation
rotation.m34 = 1.0/ -600; //關於catransform3d m34,我會在最下方給出一些理解 it
cell.layer.shadowColor = [[UIColor blackColor]CGColor];io
cell.layer.transform = rotation;table
cell.layer.anchorPoint = CGPointMake(0.5, 0.5);form
//CATransform3DIdentitytransform
[UIView animateWithDuration:0.8 animations:^{
cell.layer.transform = CATransform3DMakeRotation( (18.0*M_PI)/180, 0.0, 0.7, 0.4);
cell.alpha = 1;
} completion:^(BOOL finished) {
[UIView beginAnimations:@"rotation" context:NULL];
[UIView setAnimationDuration:0.8];
cell.layer.transform = CATransform3DIdentity;
cell.alpha = 1;
[UIView commitAnimations];
}];
}
(2).進入界面或者下拉時顯示一種彈出效果的cell效果
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
//xy方向縮放的初始值爲0.4
cell.layer.transform = CATransform3DMakeScale(0.4, 0.4, 1);
// 設置動畫時間爲1.25秒,xy方向縮放的最終值爲1
[UIView animateWithDuration:1.25 animations:^{
cell.layer.transform = CATransform3DMakeScale(1, 1, 1);
}];
}
(3).catransform3d m34的理解
transform的結構以下:
struct CATransform3D
{
CGFloat m11, m12, m13, m14;
CGFloat m21, m22, m23, m24;
CGFloat m31, m32, m33, m34;
CGFloat m41, m42, m43, m44;
};
首先要實現view(layer)的透視效果(就是近大遠小),是經過設置m34的:
CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
rotationAndPerspectiveTransform.m34 = 1.0 / -500;
m34負責z軸方向的translation(移動),m34= -1/D, 默認值是0,也就是說D無窮大,這意味layer in projection plane(投射面)和layer in world coordinate重合了。
D越小透視效果越明顯。
所謂的D,是eye(觀察者)到投射面的距離。
具體詳情可參考下方連接:
http://www.jianshu.com/p/9cbf52eb39dd