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不会接收到.这仅适用 ...
随机推荐
- Activiti学习笔记8 — UserTask私有任务的使用
每一个UserTask都会在Execution表和Task表中各产生一条记录 一.创建流程引擎对象 /** * 1.创建流程引擎对象 */ private ProcessEngine processE ...
- arm-linux-objdump 的使用
1. 查看静态库或.o 文件的组成文件 [arm@localhost gcc]$ armlinuxobjdump a libhello.a 2. 查看静态库或.o 文件的络组成部分的头部分 [a ...
- 如何优雅的在 vue 中添加权限控制
前言 在一个项目中,一些功能会涉及到重要的数据管理,为了确保数据的安全,我们会在项目中加入权限来限制每个用户的操作.作为前端,我们要做的是配合后端给到的权限数据,做页面上的各种各样的限制. 需求 因为 ...
- 两个对象值相同 (x.equals(y) == true),但却可有不同的 hash code,这句话对不对?
不对,如果两个对象x和y满足x.equals(y) == true,它们的哈希码(hash code)应当相同.Java对于eqauls方法和hashCode方法是这样规定的: (1)如果两个对象相同 ...
- vs数据库连接问题
在swagger上测试时报错:数据库连接不上 原因:在项目中修改过connectionstring,但是每次编译时本地文件中并没有更新 修改: 修改配置文件属性:不复制 —> 始终复制
- myeclipse CTRL+1功能
有时候,在myeclipse或者eclipse中自动编译代码有错误,我们把鼠标放在错误一行能够自动显示出问题原因,但是有时显示问题让人有些匪夷所思,不知所云何物. 此时可以使用<ctrl> ...
- iserver中的服务数据迁移
今天需要将iserver测试服务器上的空间数据服务(数据源是Oracle Plus)迁移到客户的正式服务器,原想需要很大的工作量,其实是这样简单: 一.保证客户的iserver环境都已安装正确.对于o ...
- 使用treeNMS管理及监控Redis
Redis做为现在web应用开发的黄金搭担组合,大量的被应用,广泛用于存储session信息,权限信息,交易作业等热数据.做为一名有10年以上JAVA开发经验的程序员,工作中项目也是广泛使用了Redi ...
- HTML引入CSS的方法
1.嵌入式 通过<style>标记,来引入CSS样式. 语法格式:<style type = “text/css”></style> 提示:<style> ...
- <Django> 高级(其他知识点)
1. 管理静态文件 什么是静态文件? 项目中的CSS.图片.js都是静态文件 配置静态文件(settings.py) # Static files (CSS, JavaScript, Images) ...