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不会接收到.这仅适用 ...
随机推荐
- java-day03
判断语句if格式 if(关系表达式){ } if...else格式: if(关系表达式){ }else{ } if...else if格式: if(关系表达式){ }else if(关系表达式){ } ...
- 调用第三方jar包_md5加密
vars.put是转换成jmeter格式
- 常见PID里面的像素大小
因为tensorflow/models里faster R-cnn目前识别的好像是按照像素比上图片大小来识别的,所以在这里统计一下各个元件的像素大小的范围 DCS:70~200
- iOS_iPhone App自动化测试
无线客户端的发展很快,特别针对是android和ios两款无线操作系统的客户端应用,相应的测试工具也应运而生,这里主要给大家介绍一些针对 iPhone App的自动化测试工具. 首先 ...
- Elasticsearch.net一些开发笔记
.net下开发es半年多了,留下些笔记 //https://www.elastic.co/guide/cn/elasticsearch/guide/current/combining-filters. ...
- BCZM : 1.6
https://blog.csdn.net/kabini/article/details/2311946 题目大意: 水房能容纳饮料的总量是V,有一批饮料,每种饮料单个容量都是2的方幂,每种饮料信息如 ...
- Controller 获取前端数据
默认支持的类型 在controller的方法的形参中直接定义上面这些类型的参数,springmvc会自动绑定. HttpServletRequest对象 HttpServletResponse对象 H ...
- System.Drawing.Imaging.ImageFormat.cs
ylbtech-System.Drawing.Imaging.ImageFormat.cs 1.程序集 System.Drawing, Version=4.0.0.0, Culture=neutral ...
- hexo 错误汇总
文章目录 发布文章遇到: 发布文章的时候出现错误: 代码推送到github,hexo g -d 半天推送不上去 记录一次hexo+coding hexo s本都没问题,hexo g -d 样式并未改变 ...
- DXP 笔记
1. 从原理图上添加 net class,快捷键 : P -> V -> C