iOS开发CATransform3D.h属性详解和方法使用
1、CATransform3D简介
layer有个属性transform,是CATransform3D类型。可以使其在三维界面作平移、缩放和旋转单独或组合动画!
CATransform3D结构体:
/* Homogeneous three-dimensional transforms.
m11:控制x方向上的缩放
m41:控制x方向上的平移 m22:控制y方向上的缩放
m42:控制y方向上的平移 m33:控制z方向上的缩放
m43:控制z方向上的平移 m21、m31、m12、m32、m13、m23控制旋转
m21:和m12一起决定z轴的旋转
m31:和m13一起决定y轴的旋转
m32:和m23一起决定x轴的旋转 m14、m24、m34、m44
m34为透视效果,要操作的这个对象要有旋转的角度,否则没有效果*/
struct CATransform3D
{
CGFloat m11, m12, m13, m14;
CGFloat m21, m22, m23, m24;
CGFloat m31, m32, m33, m34;
CGFloat m41, m42, m43, m44;
};
2、CATransform3D的简单使用和代码展示
2.1、平移
#pragma mark---平移
/* Returns a transform that translates by '(tx, ty, tz)':
* t' = [1 0 0 0; 0 1 0 0; 0 0 1 0; tx ty tz 1].
平移 tx,ty,tz对象x,y和z轴*/
CA_EXTERN CATransform3D CATransform3DMakeTranslation (CGFloat tx,
CGFloat ty, CGFloat tz);
/* Translate 't' by '(tx, ty, tz)' and return the result:
* t' = translate(tx, ty, tz) * t.
在t变换的基础上 进行平移*/
CA_EXTERN CATransform3D CATransform3DTranslate (CATransform3D t, CGFloat tx,
CGFloat ty, CGFloat tz)
CA_AVAILABLE_STARTING (10.5, 2.0, 9.0, 2.0);

- (void)transform3D{
CATransform3D transA = CATransform3DIdentity;
transA = CATransform3DMakeTranslation(, , );
[UIView animateWithDuration:
animations:^{
bgImageView.layer.transform = transA;
}
completion:^(BOOL finished) {
[UIView animateWithDuration:
animations:^{
bgImageView.layer.transform = CATransform3DTranslate(transA, -, -, );
} completion:^(BOOL finished) {
bgImageView.layer.transform = CATransform3DIdentity;
}];
}];
}
2.2、缩放
#pragma mark---缩放
/* Returns a transform that scales by `(sx, sy, sz)':
* t' = [sx 0 0 0; 0 sy 0 0; 0 0 sz 0; 0 0 0 1].
缩放tx,ty,tz对象x,y和z轴缩放比例*/
CA_EXTERN CATransform3D CATransform3DMakeScale (CGFloat sx, CGFloat sy,
CGFloat sz);
/* Scale 't' by '(sx, sy, sz)' and return the result:
* t' = scale(sx, sy, sz) * t.
在t变换的基础上 进行缩放*/
CA_EXTERN CATransform3D CATransform3DScale (CATransform3D t, CGFloat sx,
CGFloat sy, CGFloat sz)
CA_AVAILABLE_STARTING (10.5, 2.0, 9.0, 2.0);

- (void)transform3DScale{
// 1、缩放时先设置初始状态CATransform3DMakeScale(1, 1, 0);
// 2、使用CATransform3DScale时,连续缩小或放大(不能缩放后放大、放大后缩小)
// 3、直接使用CATransform3DMakeScale可以随意设置
CATransform3D transA = CATransform3DIdentity;
transA = CATransform3DMakeScale(0.5, 0.5, );
bgImageView.layer.transform = CATransform3DMakeScale(, , );
[UIView animateWithDuration:
animations:^{
bgImageView.layer.transform =transA;
}
completion:^(BOOL finished) {
[UIView animateWithDuration:
animations:^{
bgImageView.layer.transform = CATransform3DScale(transA, 0.5, 0.5, );
} completion:^(BOOL finished) {
bgImageView.layer.transform = CATransform3DIdentity;
}];
}];
}
2.3、旋转
#pragma mark---旋转
/* Returns a transform that rotates by 'angle' radians about the vector
* '(x, y, z)'. If the vector has length zero the identity transform is
* returned.
旋转
angle参数是旋转的角度
x,y,z决定了旋转围绕的中轴,取值为-1 — 1之间,
如(1,0,0),则是绕x轴旋转,(0.5,0.5,0),则是绕x轴与y轴中间45度为轴旋转*/
CA_EXTERN CATransform3D CATransform3DMakeRotation (CGFloat angle, CGFloat x,
CGFloat y, CGFloat z);
/* Rotate 't' by 'angle' radians about the vector '(x, y, z)' and return
* the result. If the vector has zero length the behavior is undefined:
* t' = rotation(angle, x, y, z) * t.
在t变换的基础上 进行旋转*/
CA_EXTERN CATransform3D CATransform3DRotate (CATransform3D t, CGFloat angle,
CGFloat x, CGFloat y, CGFloat z)
CA_AVAILABLE_STARTING (10.5, 2.0, 9.0, 2.0);

- (void)transform3DRotation{
// 1、m34实际上影响了z轴方向的translation,m34= -1/D, 默认值是0,我们需要尽可能的让m34这个值尽可能小
CATransform3D transA = CATransform3DIdentity;
transA.m34 = - 1.0 / ;
transA = CATransform3DMakeRotation(M_PI_4, , , );
[UIView animateWithDuration:
animations:^{
bgImageView.layer.transform = transA;
}
completion:^(BOOL finished) {
[UIView animateWithDuration:
animations:^{
bgImageView.layer.transform = CATransform3DRotate(transA, -M_PI_4, -, , );
} completion:^(BOOL finished) {
bgImageView.layer.transform = CATransform3DIdentity;
}];
}];
}
3、CATransform3D的其它方法说明
/* The identity transform: [1 0 0 0; 0 1 0 0; 0 0 1 0; 0 0 0 1].
最初的对象*/
CA_EXTERN const CATransform3D CATransform3DIdentity
CA_AVAILABLE_STARTING (10.5, 2.0, 9.0, 2.0); /* Returns true if 't' is the identity transform.
判断t是否是最初的对象*/
CA_EXTERN bool CATransform3DIsIdentity (CATransform3D t)
CA_AVAILABLE_STARTING (10.5, 2.0, 9.0, 2.0); /* Returns true if 'a' is exactly equal to 'b'.
判断a和b是否相同*/
CA_EXTERN bool CATransform3DEqualToTransform (CATransform3D a,
CATransform3D b)
CA_AVAILABLE_STARTING (10.5, 2.0, 9.0, 2.0); #pragma mark---other
/* Concatenate 'b' to 'a' and return the result: t' = a * b.
a和b进行叠加 返回新的对象*/
CA_EXTERN CATransform3D CATransform3DConcat (CATransform3D a, CATransform3D b)
CA_AVAILABLE_STARTING (10.5, 2.0, 9.0, 2.0); /* Invert 't' and return the result. Returns the original matrix if 't'
* has no inverse.
反向变换*/
CA_EXTERN CATransform3D CATransform3DInvert (CATransform3D t)
CA_AVAILABLE_STARTING (10.5, 2.0, 9.0, 2.0); #pragma mark--- 3D和2D转换
/* Return a transform with the same effect as affine transform 'm'.
将CGAffineTransform转化为CATransform3D*/
CA_EXTERN CATransform3D CATransform3DMakeAffineTransform (CGAffineTransform m)
CA_AVAILABLE_STARTING (10.5, 2.0, 9.0, 2.0); /* Returns true if 't' can be represented exactly by an affine transform.
判断一个CATransform3D是否可以转换为CGAffineTransform*/
CA_EXTERN bool CATransform3DIsAffine (CATransform3D t)
CA_AVAILABLE_STARTING (10.5, 2.0, 9.0, 2.0); /* Returns the affine transform represented by 't'. If 't' can not be
* represented exactly by an affine transform the returned value is
* undefined.
将CATransform3D转换为CGAffineTransform*/
CA_EXTERN CGAffineTransform CATransform3DGetAffineTransform (CATransform3D t)
CA_AVAILABLE_STARTING (10.5, 2.0, 9.0, 2.0);
iOS开发CATransform3D.h属性详解和方法使用的更多相关文章
- iOS 开发之照片框架详解(2)
一. 概况 本文接着 iOS 开发之照片框架详解,侧重介绍在前文中简单介绍过的 PhotoKit 及其与 ALAssetLibrary 的差异,以及如何基于 PhotoKit 与 AlAssetLib ...
- iOS 开发之照片框架详解之二 —— PhotoKit 详解(下)
本文链接:http://kayosite.com/ios-development-and-detail-of-photo-framework-part-three.html 这里接着前文<iOS ...
- iOS 开发之照片框架详解之二 —— PhotoKit 详解(上)
转载自:http://kayosite.com/ios-development-and-detail-of-photo-framework-part-two.html 一. 概况 本文接着 iOS 开 ...
- iOS 开发之照片框架详解
转载自:http://kayosite.com/ios-development-and-detail-of-photo-framework.html 一. 概要 在 iOS 设备中,照片和视频是相当重 ...
- iOS开发——UI篇&ScrollView详解
创建方式 1:StoryBoard/Xib 这里StoarBoard就不多说,直接拖就可以,说太多没意思,如果连这个都不会我只能先给你跪了! 2:代码: CGRect bounds = [ [ UIS ...
- IOS开发中单例模式使用详解
第一.基本概念 单例模式是一种常用的软件设计模式.在它的核心结构中只包含一个被称为单例类的特殊类.通过单例模式可以保证系统中一个类只有一个实例而且该实例易于外界访问. 第二.在IOS中使用单例模式的情 ...
- 【iOS开发必收藏】详解iOS应用程序内使用IAP/StoreKit付费、沙盒(SandBox)测试、创建测试账号流程!【2012-12-11日更新获取”产品付费数量等于0的问题”】
转的别人的 看到很多童鞋问到,为什么每次都返回数量等于0?? 其实有童鞋已经找到原因了,原因是你在 ItunesConnect 里的 “Contracts, Tax, and Banking”没有完成 ...
- 【转】 iOS开发之手势gesture详解
原文:http://www.cnblogs.com/salam/archive/2013/04/30/iOS_gesture.html 前言 在iOS中,你可以使用系统内置的手势识别 (Gesture ...
- iOS开发之手势gesture详解(二)
与其他用户界面控件交互 UIControl子类会覆盖parentView的gesture.例如当用户点击UIButton时,UIButton会接受触摸事件,它的parentView不会接收到.这仅适用 ...
随机推荐
- socket的多线程实现
步骤: 1.服务端创建ServerSocket,循环调用accept()等待客户端连接: 2.客户端创建socket并请求与服务端对话: 3.服务端接收客户端的请求,创建socket与客户端进行专线连 ...
- java锁分析
import java.util.concurrent.TimeUnit; class Phone//Phone.java ---> Phone.class Class.forName(); { ...
- 随笔-ansible-1
系统下所有的操作,从运维操作角度划分为两类: 1.文件传输 2.命令执行 系统下所有的操作,从自动化工作类型角度划分为: 1.应用部署 2.配置管理 3.任务流编排 使用root生成默认的秘钥对: # ...
- Haar分类器方法
一.Haar分类器的前世今生 二.人脸检测属于计算机视觉的范畴,早期人们的主要研究方向是人脸识别,即根据人脸来识别人物的身份,后来在复杂背景下的人脸检测需求越来越大,人脸检测也逐渐作为一个单独的研究方 ...
- java四种引用与回调函数
JAVA四种引用 java对象的引用包括: 强引用 软引用 弱引用 虚引用 Java中提供这四种引用类型主要有两个目的: 第一是可以让程序员通过代码的方式决定某些对象的生命周期: 第二是有利于JVM进 ...
- UVALive7461 - Separating Pebbles 判断两个凸包相交
//UVALive7461 - Separating Pebbles 判断两个凸包相交 #include <bits/stdc++.h> using namespace std; #def ...
- split的用法
split用法返回的是数组 使用split('')根据空格返回数组 使用split()返回一个完整的数组 使用split("",3)返回前三项,是单个的字母 不过要注意: 使用sp ...
- vue-router 的重定向-redirect
1. 我们主要在index.js重新设置路由的重新定向redirect参数 index.js import Vue from 'vue' import Router from 'vue-router' ...
- [JZOJ4665] 【GDOI2017模拟7.21】数列
题目 题目大意 给你一个数列,让你找到一个最长的连续子序列,满足在添加了至多KKK个数之后,能够变成一条公差为DDD的等差数列. 思考历程 一眼看上去似乎是一道神题-- 没有怎么花时间思考,毕竟时间都 ...
- kaptcha 实现验证码
依赖 <dependency> <groupId>com.github.penggle</groupId> <artifactId>kaptcha< ...