1、CATransform3D简介

  layer有个属性transform,是CATransform3D类型。可以使其在三维界面作平移、缩放和旋转单独或组合动画!

  CATransform3D结构体:

  1. /* Homogeneous three-dimensional transforms.
  2. m11:控制x方向上的缩放
  3. m41:控制x方向上的平移
  4.  
  5. m22:控制y方向上的缩放
  6. m42:控制y方向上的平移
  7.  
  8. m33:控制z方向上的缩放
  9. m43:控制z方向上的平移
  10.  
  11. m21、m31、m12、m32、m13、m23控制旋转
  12. m21:和m12一起决定z轴的旋转
  13. m31:和m13一起决定y轴的旋转
  14. m32:和m23一起决定x轴的旋转
  15.  
  16. m14、m24、m34、m44
  17. m34为透视效果,要操作的这个对象要有旋转的角度,否则没有效果*/
  18. struct CATransform3D
  19. {
  20. CGFloat m11, m12, m13, m14;
  21. CGFloat m21, m22, m23, m24;
  22. CGFloat m31, m32, m33, m34;
  23. CGFloat m41, m42, m43, m44;
  24. };

2、CATransform3D的简单使用和代码展示

  2.1、平移

  1. #pragma mark---平移
  2. /* Returns a transform that translates by '(tx, ty, tz)':
  3. * t' = [1 0 0 0; 0 1 0 0; 0 0 1 0; tx ty tz 1].
  4. 平移 tx,ty,tz对象x,y和z轴*/
  5. CA_EXTERN CATransform3D CATransform3DMakeTranslation (CGFloat tx,
  6. CGFloat ty, CGFloat tz);
  7. /* Translate 't' by '(tx, ty, tz)' and return the result:
  8. * t' = translate(tx, ty, tz) * t.
  9. 在t变换的基础上 进行平移*/
  10. CA_EXTERN CATransform3D CATransform3DTranslate (CATransform3D t, CGFloat tx,
  11. CGFloat ty, CGFloat tz)
  12. CA_AVAILABLE_STARTING (10.5, 2.0, 9.0, 2.0);

  1. - (void)transform3D{
  2. CATransform3D transA = CATransform3DIdentity;
  3. transA = CATransform3DMakeTranslation(, , );
  4. [UIView animateWithDuration:
  5. animations:^{
  6. bgImageView.layer.transform = transA;
  7. }
  8. completion:^(BOOL finished) {
  9. [UIView animateWithDuration:
  10. animations:^{
  11. bgImageView.layer.transform = CATransform3DTranslate(transA, -, -, );
  12. } completion:^(BOOL finished) {
  13. bgImageView.layer.transform = CATransform3DIdentity;
  14. }];
  15. }];
  16. }

  2.2、缩放

  1. #pragma mark---缩放
  2. /* Returns a transform that scales by `(sx, sy, sz)':
  3. * t' = [sx 0 0 0; 0 sy 0 0; 0 0 sz 0; 0 0 0 1].
  4. 缩放tx,ty,tz对象x,y和z轴缩放比例*/
  5. CA_EXTERN CATransform3D CATransform3DMakeScale (CGFloat sx, CGFloat sy,
  6. CGFloat sz);
  7. /* Scale 't' by '(sx, sy, sz)' and return the result:
  8. * t' = scale(sx, sy, sz) * t.
  9. 在t变换的基础上 进行缩放*/
  10. CA_EXTERN CATransform3D CATransform3DScale (CATransform3D t, CGFloat sx,
  11. CGFloat sy, CGFloat sz)
  12. CA_AVAILABLE_STARTING (10.5, 2.0, 9.0, 2.0);

  1. - (void)transform3DScale{
  2. // 1、缩放时先设置初始状态CATransform3DMakeScale(1, 1, 0);
  3. // 2、使用CATransform3DScale时,连续缩小或放大(不能缩放后放大、放大后缩小)
  4. // 3、直接使用CATransform3DMakeScale可以随意设置
  5. CATransform3D transA = CATransform3DIdentity;
  6. transA = CATransform3DMakeScale(0.5, 0.5, );
  7. bgImageView.layer.transform = CATransform3DMakeScale(, , );
  8. [UIView animateWithDuration:
  9. animations:^{
  10. bgImageView.layer.transform =transA;
  11. }
  12. completion:^(BOOL finished) {
  13. [UIView animateWithDuration:
  14. animations:^{
  15. bgImageView.layer.transform = CATransform3DScale(transA, 0.5, 0.5, );
  16. } completion:^(BOOL finished) {
  17. bgImageView.layer.transform = CATransform3DIdentity;
  18. }];
  19. }];
  20. }

  2.3、旋转

  1. #pragma mark---旋转
  2. /* Returns a transform that rotates by 'angle' radians about the vector
  3. * '(x, y, z)'. If the vector has length zero the identity transform is
  4. * returned.
  5. 旋转
  6. angle参数是旋转的角度
  7. x,y,z决定了旋转围绕的中轴,取值为-1 — 1之间,
  8. 如(1,0,0),则是绕x轴旋转,(0.5,0.5,0),则是绕x轴与y轴中间45度为轴旋转*/
  9. CA_EXTERN CATransform3D CATransform3DMakeRotation (CGFloat angle, CGFloat x,
  10. CGFloat y, CGFloat z);
  11. /* Rotate 't' by 'angle' radians about the vector '(x, y, z)' and return
  12. * the result. If the vector has zero length the behavior is undefined:
  13. * t' = rotation(angle, x, y, z) * t.
  14. 在t变换的基础上 进行旋转*/
  15. CA_EXTERN CATransform3D CATransform3DRotate (CATransform3D t, CGFloat angle,
  16. CGFloat x, CGFloat y, CGFloat z)
  17. CA_AVAILABLE_STARTING (10.5, 2.0, 9.0, 2.0);

  1. - (void)transform3DRotation{
  2. // 1、m34实际上影响了z轴方向的translation,m34= -1/D, 默认值是0,我们需要尽可能的让m34这个值尽可能小
  3. CATransform3D transA = CATransform3DIdentity;
  4. transA.m34 = - 1.0 / ;
  5. transA = CATransform3DMakeRotation(M_PI_4, , , );
  6. [UIView animateWithDuration:
  7. animations:^{
  8. bgImageView.layer.transform = transA;
  9. }
  10. completion:^(BOOL finished) {
  11. [UIView animateWithDuration:
  12. animations:^{
  13. bgImageView.layer.transform = CATransform3DRotate(transA, -M_PI_4, -, , );
  14. } completion:^(BOOL finished) {
  15. bgImageView.layer.transform = CATransform3DIdentity;
  16. }];
  17. }];
  18. }

3、CATransform3D的其它方法说明

  1. /* The identity transform: [1 0 0 0; 0 1 0 0; 0 0 1 0; 0 0 0 1].
  2. 最初的对象*/
  3. CA_EXTERN const CATransform3D CATransform3DIdentity
  4. CA_AVAILABLE_STARTING (10.5, 2.0, 9.0, 2.0);
  5.  
  6. /* Returns true if 't' is the identity transform.
  7. 判断t是否是最初的对象*/
  8. CA_EXTERN bool CATransform3DIsIdentity (CATransform3D t)
  9. CA_AVAILABLE_STARTING (10.5, 2.0, 9.0, 2.0);
  10.  
  11. /* Returns true if 'a' is exactly equal to 'b'.
  12. 判断a和b是否相同*/
  13. CA_EXTERN bool CATransform3DEqualToTransform (CATransform3D a,
  14. CATransform3D b)
  15. CA_AVAILABLE_STARTING (10.5, 2.0, 9.0, 2.0);
  16.  
  17. #pragma mark---other
  18. /* Concatenate 'b' to 'a' and return the result: t' = a * b.
  19. a和b进行叠加 返回新的对象*/
  20. CA_EXTERN CATransform3D CATransform3DConcat (CATransform3D a, CATransform3D b)
  21. CA_AVAILABLE_STARTING (10.5, 2.0, 9.0, 2.0);
  22.  
  23. /* Invert 't' and return the result. Returns the original matrix if 't'
  24. * has no inverse.
  25. 反向变换*/
  26. CA_EXTERN CATransform3D CATransform3DInvert (CATransform3D t)
  27. CA_AVAILABLE_STARTING (10.5, 2.0, 9.0, 2.0);
  28.  
  29. #pragma mark--- 3D2D转换
  30. /* Return a transform with the same effect as affine transform 'm'.
  31. 将CGAffineTransform转化为CATransform3D*/
  32. CA_EXTERN CATransform3D CATransform3DMakeAffineTransform (CGAffineTransform m)
  33. CA_AVAILABLE_STARTING (10.5, 2.0, 9.0, 2.0);
  34.  
  35. /* Returns true if 't' can be represented exactly by an affine transform.
  36. 判断一个CATransform3D是否可以转换为CGAffineTransform*/
  37. CA_EXTERN bool CATransform3DIsAffine (CATransform3D t)
  38. CA_AVAILABLE_STARTING (10.5, 2.0, 9.0, 2.0);
  39.  
  40. /* Returns the affine transform represented by 't'. If 't' can not be
  41. * represented exactly by an affine transform the returned value is
  42. * undefined.
  43. 将CATransform3D转换为CGAffineTransform*/
  44. CA_EXTERN CGAffineTransform CATransform3DGetAffineTransform (CATransform3D t)
  45. CA_AVAILABLE_STARTING (10.5, 2.0, 9.0, 2.0);

iOS开发CATransform3D.h属性详解和方法使用的更多相关文章

  1. iOS 开发之照片框架详解(2)

    一. 概况 本文接着 iOS 开发之照片框架详解,侧重介绍在前文中简单介绍过的 PhotoKit 及其与 ALAssetLibrary 的差异,以及如何基于 PhotoKit 与 AlAssetLib ...

  2. iOS 开发之照片框架详解之二 —— PhotoKit 详解(下)

    本文链接:http://kayosite.com/ios-development-and-detail-of-photo-framework-part-three.html 这里接着前文<iOS ...

  3. iOS 开发之照片框架详解之二 —— PhotoKit 详解(上)

    转载自:http://kayosite.com/ios-development-and-detail-of-photo-framework-part-two.html 一. 概况 本文接着 iOS 开 ...

  4. iOS 开发之照片框架详解

    转载自:http://kayosite.com/ios-development-and-detail-of-photo-framework.html 一. 概要 在 iOS 设备中,照片和视频是相当重 ...

  5. iOS开发——UI篇&ScrollView详解

    创建方式 1:StoryBoard/Xib 这里StoarBoard就不多说,直接拖就可以,说太多没意思,如果连这个都不会我只能先给你跪了! 2:代码: CGRect bounds = [ [ UIS ...

  6. IOS开发中单例模式使用详解

    第一.基本概念 单例模式是一种常用的软件设计模式.在它的核心结构中只包含一个被称为单例类的特殊类.通过单例模式可以保证系统中一个类只有一个实例而且该实例易于外界访问. 第二.在IOS中使用单例模式的情 ...

  7. 【iOS开发必收藏】详解iOS应用程序内使用IAP/StoreKit付费、沙盒(SandBox)测试、创建测试账号流程!【2012-12-11日更新获取”产品付费数量等于0的问题”】

    转的别人的 看到很多童鞋问到,为什么每次都返回数量等于0?? 其实有童鞋已经找到原因了,原因是你在 ItunesConnect 里的 “Contracts, Tax, and Banking”没有完成 ...

  8. 【转】 iOS开发之手势gesture详解

    原文:http://www.cnblogs.com/salam/archive/2013/04/30/iOS_gesture.html 前言 在iOS中,你可以使用系统内置的手势识别 (Gesture ...

  9. iOS开发之手势gesture详解(二)

    与其他用户界面控件交互 UIControl子类会覆盖parentView的gesture.例如当用户点击UIButton时,UIButton会接受触摸事件,它的parentView不会接收到.这仅适用 ...

随机推荐

  1. Activiti学习笔记8 — UserTask私有任务的使用

    每一个UserTask都会在Execution表和Task表中各产生一条记录 一.创建流程引擎对象 /** * 1.创建流程引擎对象 */ private ProcessEngine processE ...

  2. arm-linux-objdump 的使用

    1. 查看静态库或.o 文件的组成文件 [arm@localhost gcc]$ arm­linux­objdump ­a libhello.a 2. 查看静态库或.o 文件的络组成部分的头部分 [a ...

  3. 如何优雅的在 vue 中添加权限控制

    前言 在一个项目中,一些功能会涉及到重要的数据管理,为了确保数据的安全,我们会在项目中加入权限来限制每个用户的操作.作为前端,我们要做的是配合后端给到的权限数据,做页面上的各种各样的限制. 需求 因为 ...

  4. 两个对象值相同 (x.equals(y) == true),但却可有不同的 hash code,这句话对不对?

    不对,如果两个对象x和y满足x.equals(y) == true,它们的哈希码(hash code)应当相同.Java对于eqauls方法和hashCode方法是这样规定的: (1)如果两个对象相同 ...

  5. vs数据库连接问题

    在swagger上测试时报错:数据库连接不上 原因:在项目中修改过connectionstring,但是每次编译时本地文件中并没有更新 修改: 修改配置文件属性:不复制 —> 始终复制

  6. myeclipse CTRL+1功能

    有时候,在myeclipse或者eclipse中自动编译代码有错误,我们把鼠标放在错误一行能够自动显示出问题原因,但是有时显示问题让人有些匪夷所思,不知所云何物. 此时可以使用<ctrl> ...

  7. iserver中的服务数据迁移

    今天需要将iserver测试服务器上的空间数据服务(数据源是Oracle Plus)迁移到客户的正式服务器,原想需要很大的工作量,其实是这样简单: 一.保证客户的iserver环境都已安装正确.对于o ...

  8. 使用treeNMS管理及监控Redis

    Redis做为现在web应用开发的黄金搭担组合,大量的被应用,广泛用于存储session信息,权限信息,交易作业等热数据.做为一名有10年以上JAVA开发经验的程序员,工作中项目也是广泛使用了Redi ...

  9. HTML引入CSS的方法

    1.嵌入式 通过<style>标记,来引入CSS样式. 语法格式:<style type = “text/css”></style> 提示:<style> ...

  10. <Django> 高级(其他知识点)

    1. 管理静态文件 什么是静态文件? 项目中的CSS.图片.js都是静态文件 配置静态文件(settings.py) # Static files (CSS, JavaScript, Images) ...