zoukankan      html  css  js  c++  java
  • swift--CATransform3D的简单介绍

    今天来了解下CATransform3D的一些基本的知识。
    CATransform3D是一个用于处理3D形变的类,其可以改变控件的平移、缩放、旋转、斜交等,其坐标系统采用的是三维坐标系,即向右为x轴正方向,向下为y轴正方向,垂直屏幕向外为z轴正方向。

    今天来了解下CATransform3D的一些基本的知识。
    1. CATransform3D是一个用于处理3D形变的类,其可以改变控件的平移、缩放、旋转、斜交等,其坐标系统采用的是三维坐标系,即向右为x轴正方向,向下为y轴正方向,垂直屏幕向外为z轴正方向

    public func CATransform3DMakeTranslation( tx: CGFloat,  ty: CGFloat, _ tz: CGFloat) -> CATransform3D

    当tx为正值时,会向x轴正方向平移,反之,则向x轴负方向平移;当ty为正值时,会向y轴正方向平移,反之,则向y轴负方向平移;当tz为正值时,会向z轴正方向平移,反之,则向z轴负方向平移。

    2. CATransform3DTranslate实现以一个已经存在的形变为基准,在x轴方向上平移x单位,在y轴方向上平移y单位,在z轴方向上平移z单位。
    格式:

    public func CATransform3DTranslate( t: CATransform3D,  tx: CGFloat,  ty: CGFloat,  tz: CGFloat) -> CATransform3D

    3. CATransform3DMakeScale实现以初始位置为基准,在x轴方向上缩放x倍,在y轴方向上缩放y倍,在z轴方向上缩放z倍。
    格式:

    public func CATransform3DMakeScale( sx: CGFloat,  sy: CGFloat,  sz: CGFloat) -> CATransform3D


    当sx为正值时,会在x轴方向上缩放x倍,反之,则在缩放的基础上沿着竖直线翻转;当sy为正值时,会在y轴方向上缩放y倍,反之,则在缩放的基础上沿着水平线翻转。

    4. CATransform3DScale实现以一个已经存在的形变为基准,在x轴方向上缩放x倍,在y轴方向上缩放y倍,在z轴方向上缩放z倍。
    格式:

    public func CATransform3DScale( t: CATransform3D,  sx: CGFloat,  sy: CGFloat,  sz: CGFloat) -> CATransform3D

    5. CATransform3DMakeRotation实现以初始位置为基准,在x轴,y轴,z轴方向上逆时针旋转angle弧度(弧度=π/180×角度,M_PI弧度代表180角度),x,y,z三个参数只分是否为0。
    格式:

    public func CATransform3DMakeRotation( angle: CGFloat,  x: CGFloat,  y: CGFloat,  z: CGFloat) -> CATransform3D

    当x,y,z值为0时,代表在该轴方向上不进行旋转,当值为1时,代表在该轴方向上进行逆时针旋转,当值为-1时,代表在该轴方向上进行顺时针旋转。

    6. CATransform3DRotate实现以一个已经存在的形变为基准,在x轴,y轴,z轴方向上逆时针旋转angle弧度(弧度=π/180×角度,M_PI弧度代表180角度),x,y,z三个参数只分是否为0。
    格式:

    public func CATransform3DRotate( t: CATransform3D,  angle: CGFloat,  x: CGFloat,  y: CGFloat,  z: CGFloat) -> CATransform3D

    方法调用,调用方法都是一样的:

    如下:

    以一个旋转动画为例:

    self.myView.frame = CGRect(x:30,y:280,kScreenWidth-60,height:150)
    self.myView.backgroundColor = UIColor.red
    self.view.addSubview(self.myView)
    var tranform = CATransform3D()
    tranform = CATransform3DMakeRotation(CGFloat(Double.pi * 160 / 180 ), 0, 1, 0);
    
    UIView.animate(withDuration: 3) {
    
       self.myView.layer.transform = tranform
    }

    创建一个view,然后创建一个tranform,然后运行就可以了,角度的写法原来的M_PI废弃了,现在使用Double.pi/CGFloat.pi来进行设置!

    附一个给表格cell的显示动画:

    //设置cell的显示动画
    func tableView(tableView: UITableView!, willDisplayCell cell: UITableViewCell!,
        forRowAtIndexPath indexPath: NSIndexPath!){
        //设置cell的显示动画为3D缩放
        //xy方向缩放的初始值为0.1
        cell.layer.transform = CATransform3DMakeScale(0.1, 0.1, 1)
        //设置动画时间为0.25秒,xy方向缩放的最终值为1
        UIView.animateWithDuration(0.25, animations: {
            cell.layer.transform=CATransform3DMakeScale(1, 1, 1)
        })
    }

    大体的实现思路就是这样的,可以一个一个方法的试试!动画就是平移/旋转/缩放几种样式!

  • 相关阅读:
    【JavaWeb】Spring+SpringMVC+MyBatis+SpringSecurity+EhCache+JCaptcha 完整Web基础框架(前言)
    【CityHunter】游戏流程设计及技术要点
    lua table操作
    python线程池(转)
    windows通过企业内部授权服务器激活方法
    贝叶斯定理(转)
    python 日期计算
    python 过滤 b'及提取 cmd命令返回值
    python 连接MySQL数据库
    python 获取昨天的日期
  • 原文地址:https://www.cnblogs.com/hero11223/p/7699696.html
Copyright © 2011-2022 走看看