-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
 
//参考资料:http://beyondvincent.com/2014/01/13/2014-01-13-animation-tableview-cell/
 
//1、配置CATransform3D的内容
 
    CATransform3D transform;
 
    //该CATransform3DMakeRotation函数创建了一个转变,将在三维轴坐标系以任意弧度旋转层。
 
    transform = CATransform3DMakeRotation( (90.0*M_PI)/180, 0.0, 0.7, 0.4);
    //
    //transform = CATransform3DMakeRotation(0.78, 0.0, 0.7, 0.4);
    //
    //transform = CATransform3DMakeRotation(radians(45.0), 0.0, 1.0, 0.0);
    /*
     参数:第一个参数是旋转的角度,对象按照你设定的角度的最短距离去旋转,后面三个参数分别是xyz(-1~1之间的值)代表的一个向量值
 
     a、
 
     //沿Y轴旋转
 
     transform = CATransform3DMakeRotation( (90.0*M_PI)/180, 0.0, 1.0, 0.0);
 
     //沿X轴旋转
 
     transform = CATransform3DMakeRotation( (90.0*M_PI)/180, 1.0, 0.0, 0.0);
 
     //沿Z轴旋转
 
     transform = CATransform3DMakeRotation( (90.0*M_PI)/180, 0.0, 0.0, 1.0);
 
     b、
 
     0.78,用在前面的例子,是由角度值经计算转化为弧度值。要把角度值转化为弧度值,可以使用一个简单的公式Mπ/180 。
 
     例如, 45π/180 = 45 ( 3.1415 ) / 180 = 0.7853 。
 
     double radians(float degrees) {
 
     return ( degrees * 3.14159265 ) / 180.0;
 
     }
 
     //当你创建一个转换的时候,你将要调用这个方法:
 
     transform = CATransform3DMakeRotation(radians(45.0), 0.0, 1.0, 0.0);
 
     */
 
    transform.m34 = 1.0/ -600;
 
    /*
 
     transform的结构如下:
 
     struct CATransform3D
 
     {
 
     相关资料:http://blog.csdn.net/ch_soft/article/details/7351896/
 
     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(观察者)到投射面的距离。
 
     */
 
 
// 2. 定义cell的初始状态
 
 
    /*影子的颜色。默认为不透明的黑色。颜色创建从目前的模式是不受支持的。可以做成动画。*/
 
    cell.layer.shadowColor = [[UIColor blackColor]CGColor];
 
    /* 影子偏移量。默认为(0,-3)。可以做成动画。 */
 
    cell.layer.shadowOffset = CGSizeMake(10, 10);
 
    cell.alpha = 0;
 
    cell.layer.transform = transform;
 
    /*定义层的边界矩形的锚点,点上归一化层坐标- '(0,0)的左下角边界矩形”(1,1)”是右上角。默认为'(0.5,0.5)”,即边界矩形的中心,可以做成动画。*/
 
    cell.layer.anchorPoint = CGPointMake(0, 0.5);
 
 
 
// 3. 定义cell的最终状态,并提交动画
 
 
    [UIView beginAnimations:@"transform" context:NULL];
 
    [UIView setAnimationDuration:0.5];//慢动作
 
    cell.layer.transform = CATransform3DIdentity;/* Returns true if 't' is the identity transform. 还原的意思吧?*/
 
    cell.alpha = 1;
 
    cell.layer.shadowOffset = CGSizeMake(0, 0);
 
    cell.frame = CGRectMake(0, cell.frame.origin.y, cell.frame.size.width, cell.frame.size.height);
 
    [UIView commitAnimations];
}
posted on 2015-11-09 11:46  韩江河  阅读(463)  评论(0编辑  收藏  举报