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不会接收到.这仅适用 ...
随机推荐
- 17-MySQL-Ubuntu-数据表的查询-分页(六)
分页(limit) 注: (1)limit位于SQL语句的最后面; (2)limit 2; 2表示查询前两条数据; (3)limit 0,2; 0表示查询第1页的起始数据的下标,2表示每页有两条数据 ...
- C#枚举转化示例大全,数字或字符串转枚举
本文重点举例说明C#枚举的用法,数字转化为枚举.枚举转化为数字及其枚举数值的判断,以下是具体的示例: 先举两个简单的例子,然后再详细的举例说明: 字符串转换成枚举:DayOfWeek week=(Da ...
- Codeforces 479【D】div3
题目链接:http://codeforces.com/problemset/problem/977/D 题意:给你一个数字序列,定了一个游戏规则.你可以对当前数字进行两个操作 1./ 3 如果这个数 ...
- 基于NEO4J的高级检索功能
基于NEO4J的高级检索 一.需求 二.创建索引 1.索引自动更新配置 2.执行带有索引自动更新配置的过程 三.查询索引 1.LUCENE查询语法 2.实现高级检索的核心:LUCENE QUERY语句 ...
- JS对象 charAt() 方法可返回指定位置的字符。返回的字符是长度为 1 的字符串。
返回指定位置的字符 charAt() 方法可返回指定位置的字符.返回的字符是长度为 1 的字符串. 语法: stringObject.charAt(index) 参数说明: 注意:1.字符串中第一个字 ...
- swing 托盘
直接上方法, 不过有些问题要注意,最后会说明! private void systemTray() { if (SystemTray.isSupported()) { // 判断系统是否支持托盘功能. ...
- 深度探索C++对象模型之第一章:关于对象之关键词所引起的差异
————如果不是为了努力维护与C之间的兼容性,C++远比现在简单的多. 如果一个程序员渴望学习C++,但是他却发现书中没有熟悉的struct,一定会苦恼,将这个主题包含到C++里,可以提供语言转移时的 ...
- 用于扩展目标跟踪的笛卡尔B-Spline车辆模型
(哥廷根大学) 摘要 文章提出了一种表示空间扩展物体轮廓的新方法,该方法适用于采用激光雷达跟踪未知尺寸和方向的车辆.我们在笛卡尔坐标系中使用二次均匀周期的B-Splines直接表示目标的星 - 凸形状 ...
- Algo: Two Sum
类似的题目可以用HashTable的思想解决. 1.Two Sum Given an array of integers, return indices of the two numbers such ...
- Altera设置Virtual Pin
1,GUI方式 大家都知道的,assignment editor –> category –> logic options –> to –> virtual pin –> ...