CoreGraphics.h

CGAffineTransform rotation = CGAffineTransformMakeRotation(M_PI_2);[xxx setTransform:rotation];呵呵就这么简单的两行代码就可以实现了!

顺便记录一些常量,以后用的着!

#define M_E         2.71828182845904523536028747135266250   e#define M_LOG2E     1.44269504088896340735992468100189214   log 2e#define M_LOG10E    0.434294481903251827651128918916605082  log 10e#define M_LN2       0.693147180559945309417232121458176568  log e2#define M_LN10      2.30258509299404568401799145468436421   log e10#define M_PI        3.14159265358979323846264338327950288   pi#define M_PI_2      1.57079632679489661923132169163975144   pi/2#define M_PI_4      0.785398163397448309615660845819875721  pi/4#define M_1_PI      0.318309886183790671537767526745028724  1/pi#define M_2_PI      0.636619772367581343075535053490057448  2/pi#define M_2_SQRTPI  1.12837916709551257389615890312154517   2/sqrt(pi)#define M_SQRT2     1.41421356237309504880168872420969808   sqrt(2)#define M_SQRT1_2   0.707106781186547524400844362104849039  1/sqrt(2)

from:http://donbe.blog.163.com/blog/static/138048021201061054243442/CGAffineTransformMakeTranslation(width, 0.0);是改变位置的,

CGAffineTransformRotate(transform, M_PI);是旋转的。

CGAffineTransformMakeRotation(-M_PI);也是旋转的

transform = CGAffineTransformScale(transform, -1.0, 1.0);是缩放的。

view.transform = CGAffineTransformIdentity;线性代数里面讲的矩阵变换,这个是恒等变换当 你改变过一个view.transform属性或者view.layer.transform的时候需要恢复默认状态的话,记得先把他们重置可以使用

view.transform = CGAffineTransformIdentity,

或者view.layer.transform = CATransform3DIdentity,

假设你一直不断的改变一个view.transform的属性,而每次改变之前没有重置的话,你会发现后来 的改变和你想要的发生变化了,不是你真正想要的结果

Quartz转换实现的原理:Quartz把绘图分成两个部分,

用户空间,即和设备无关,

设备空间,

用户空间和设备空间中间存在一个转换矩阵 : CTM

本章实质是讲解CTM

Quartz提供的3大功能

移动,旋转,缩放

演示如下,首先加载一张图片

void CGContextDrawImage (

CGContextRef c,

CGRect rect,

CGImageRef image

);

移动函数

CGContextTranslateCTM (myContext, 100, 50);

旋转函数

include <math.h>

static inline double radians (double degrees) {return degrees * M_PI/180;}

CGContextRotateCTM (myContext, radians(–45.));

缩放

CGContextScaleCTM (myContext, .5, .75);

翻转, 两种转换合成后的效果,先把图片移动到右上角,然后旋转180度

CGContextTranslateCTM (myContext, w,h);

CGContextRotateCTM (myContext, radians(-180.));

组合几个动作

CGContextTranslateCTM (myContext, w/4, 0);

CGContextScaleCTM (myContext, .25,  .5);

CGContextRotateCTM (myContext, radians ( 22.));

CGContextRotateCTM (myContext, radians ( 22.));

CGContextScaleCTM (myContext, .25,  .5);

CGContextTranslateCTM (myContext, w/4, 0);

上面是通过直接修改当前的ctm实现3大效果,下面是通过创建Affine Transforms,然后连接ctm实现同样的3种效果

这样做的好处是可以重用这个Affine Transforms

应用Affine Transforms 到ctm的函数

void CGContextConcatCTM (

CGContextRef c,

CGAffineTransform transform

);

Creating Affine Transforms

移动效果

CGAffineTransform CGAffineTransformMakeTranslation (

CGFloat tx,

CGFloat ty

);

CGAffineTransform CGAffineTransformTranslate (

CGAffineTransform t,

CGFloat tx,

CGFloat ty

);

旋转效果

CGAffineTransform CGAffineTransformMakeRotation (

CGFloat angle

);

CGAffineTransform CGAffineTransformRotate (

CGAffineTransform t,

CGFloat angle

);

缩放效果

CGAffineTransform CGAffineTransformMakeScale (

CGFloat sx,

CGFloat sy

);

CGAffineTransform CGAffineTransformScale (

CGAffineTransform t,

CGFloat sx,

CGFloat sy

);

反转效果

CGAffineTransform CGAffineTransformInvert (

CGAffineTransform t

);

只对局部产生效果

CGRect CGRectApplyAffineTransform (

CGRect rect,

CGAffineTransform t

);

判断两个AffineTrans是否相等

bool CGAffineTransformEqualToTransform (

CGAffineTransform t1,

CGAffineTransform t2

);

获得Affine Transform

CGAffineTransform CGContextGetUserSpaceToDeviceSpaceTransform (

CGContextRef c

);

下面的函数只起到查看的效果,比如看一下这个用户空间的点,转换到设备空间去坐标是多少

CGPoint CGContextConvertPointToDeviceSpace (

CGContextRef c,

CGPoint point

);

CGPoint CGContextConvertPointToUserSpace (

CGContextRef c,

CGPoint point

);

CGSize CGContextConvertSizeToDeviceSpace (

CGContextRef c,

CGSize size

);

CGSize CGContextConvertSizeToUserSpace (

CGContextRef c,

CGSize size

);

CGRect CGContextConvertRectToDeviceSpace (

CGContextRef c,

CGRect rect

);

CGRect CGContextConvertRectToUserSpace (

CGContextRef c,

CGRect rect

);

CTM真正的数学行为

这个转换矩阵其实是一个 3x3的 举证

如下图

下面举例说明几个转换运算的数学实现

x y 是原先点的坐标

下面是从用户坐标转换到设备坐标的计算公式

下面是一个identity matrix,就是输入什么坐标,出来什么坐标,没有转换

最终的计算结果是 x=x,y=y,

可以用函数判断这个矩阵是不是一个 identity matrix

bool CGAffineTransformIsIdentity (

CGAffineTransform t

);

参考:http://developer.apple.com/library/ios/#documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_affine/dq_affine.html

- (void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation   duration:(NSTimeInterval)duration

{

if (toInterfaceOrientation == UIInterfaceOrientationPortrait)

{

b=YES;

self.view=mainvv;

self.view.transform = CGAffineTransformIdentity;

self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(0));

self.view.bounds = CGRectMake(0.0, 0.0, 768.0, 1004.0);

}

else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)

{

b=NO;

self.view = self.vv;

self.view.transform = CGAffineTransformIdentity;

self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90));

self.view.bounds = CGRectMake(0.0, 0.0, 1024.0, 748.0);

}

else if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)

{

b=YES;

self.view=mainvv;

self.view.transform = CGAffineTransformIdentity;

self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(180));

self.view.bounds = CGRectMake(0.0, 0.0, 768.0, 1004.0);

}

else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)

{

b=NO;

self.view = self.vv;

self.view.transform = CGAffineTransformIdentity;

self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90));

self.view.bounds = CGRectMake(0.0, 0.0, 1024.0, 748.0);

}

}

3

Quartz转换实现的原理:Quartz把绘图分成两个部分,

用户空间,即和设备无关,

设备空间,

用户空间和设备空间中间存在一个转换矩阵 : CTM

本章实质是讲解CTM

Quartz提供的3大功能

移动,旋转,缩放

演示如下,首先加载一张图片

void CGContextDrawImage (

CGContextRef c,

CGRect rect,

CGImageRef image

);

移动函数

CGContextTranslateCTM (myContext, 100, 50);

旋转函数

include <math.h>

static inline double radians (double degrees) {return degrees * M_PI/180;}

CGContextRotateCTM (myContext, radians(–45.));

缩放

CGContextScaleCTM (myContext, .5, .75);

翻转, 两种转换合成后的效果,先把图片移动到右上角,然后旋转180度

CGContextTranslateCTM (myContext, w,h);

CGContextRotateCTM (myContext, radians(-180.));

组合几个动作

CGContextTranslateCTM (myContext, w/4, 0);

CGContextScaleCTM (myContext, .25,  .5);

CGContextRotateCTM (myContext, radians ( 22.));

CGContextRotateCTM (myContext, radians ( 22.));

CGContextScaleCTM (myContext, .25,  .5);

CGContextTranslateCTM (myContext, w/4, 0);

上面是通过直接修改当前的ctm实现3大效果,下面是通过创建Affine Transforms,然后连接ctm实现同样的3种效果

这样做的好处是可以重用这个Affine Transforms

应用Affine Transforms 到ctm的函数

void CGContextConcatCTM (

CGContextRef c,

CGAffineTransform transform

);

Creating Affine Transforms

移动效果

CGAffineTransform CGAffineTransformMakeTranslation (

CGFloat tx,

CGFloat ty

);

CGAffineTransform CGAffineTransformTranslate (

CGAffineTransform t,

CGFloat tx,

CGFloat ty

);

旋转效果

CGAffineTransform CGAffineTransformMakeRotation (

CGFloat angle

);

CGAffineTransform CGAffineTransformRotate (

CGAffineTransform t,

CGFloat angle

);

缩放效果

CGAffineTransform CGAffineTransformMakeScale (

CGFloat sx,

CGFloat sy

);

CGAffineTransform CGAffineTransformScale (

CGAffineTransform t,

CGFloat sx,

CGFloat sy

);

反转效果

CGAffineTransform CGAffineTransformInvert (

CGAffineTransform t

);

只对局部产生效果

CGRect CGRectApplyAffineTransform (

CGRect rect,

CGAffineTransform t

);

判断两个AffineTrans是否相等

bool CGAffineTransformEqualToTransform (

CGAffineTransform t1,

CGAffineTransform t2

);

获得Affine Transform

CGAffineTransform CGContextGetUserSpaceToDeviceSpaceTransform (

CGContextRef c

);

下面的函数只起到查看的效果,比如看一下这个用户空间的点,转换到设备空间去坐标是多少

CGPoint CGContextConvertPointToDeviceSpace (

CGContextRef c,

CGPoint point

);

CGPoint CGContextConvertPointToUserSpace (

CGContextRef c,

CGPoint point

);

CGSize CGContextConvertSizeToDeviceSpace (

CGContextRef c,

CGSize size

);

CGSize CGContextConvertSizeToUserSpace (

CGContextRef c,

CGSize size

);

CGRect CGContextConvertRectToDeviceSpace (

CGContextRef c,

CGRect rect

);

CGRect CGContextConvertRectToUserSpace (

CGContextRef c,

CGRect rect

);

CTM真正的数学行为

这个转换矩阵其实是一个 3x3的 举证

如下图

下面举例说明几个转换运算的数学实现

x y 是原先点的坐标

下面是从用户坐标转换到设备坐标的计算公式

下面是一个identity matrix,就是输入什么坐标,出来什么坐标,没有转换

最终的计算结果是 x=x,y=y,

可以用函数判断这个矩阵是不是一个 identity matrix

bool CGAffineTransformIsIdentity (

CGAffineTransform t

);

CGAffineTransformMakeRotation(180 / 180.0 * M_PI );//180移动。上下互换。

移动矩阵

缩放矩阵

旋转矩阵

旋转加移动矩阵

http://www.cnblogs.com/pengyingh/articles/2378732.html

IOSView翻转扭矩位移的更多相关文章

  1. iOS Transform坐标变化

    在使用CGContext时,由于Quartz 2D与UIKit坐标不一致,所以需要对context进行再一次的变化,达到预期的效果. 1. 不同坐标原点介绍 在Quartz 2D中,坐标原点在画布的左 ...

  2. css3Transitions 实现的鼠标经过图标位移、旋转、翻转、发光、淡入淡出等多种特效

    HTML如下:   1 <div class="container"> 3 <!--特效1 --> <section id="set-1&q ...

  3. python自学笔记(六)二进制与位移

    一.二进制 a = 1 bin(a)-->ob1  #python内置方法 ob 表示二进整型制格式 二.难缠符号 1.位移二进制的位 >> 右位移,想象成 切肉切去最后一位 例如 ...

  4. 正经学C#_位移与其位移运算符[c#入门经典]

    在c#入门经典一书中,最为糟糕的一节就是位移了,完全没有讲明白,也没有说全,似乎只是轻轻点了一下何为位移,带了两次原码和补码,完全不理会是否明白不明白.这一点这本书很差.因为此书说了,在大多数应用开发 ...

  5. 纯CSS 3D翻转一个面(翻转导航菜单 立方体)

    在做练习的时候学到css的翻转导航菜单,原代码有点让人头疼,通过对其css的参数一点点研究了其实现过程. 这里推荐大家研究这个3D翻转动画的代码. 我的github:swarz,欢迎给老弟我++星星 ...

  6. 原生js如何实现图片翻转旋转效果?

    原生js如何实现图片翻转旋转效果? 一.总结 1.通过给元素设置style中的transition来实现的. 2.我昨天纠结的效果全部可以通过精读这个代码后实现. 二.原生js如何实现图片翻转旋转效果 ...

  7. [LeetCode] Reverse Vowels of a String 翻转字符串中的元音字母

    Write a function that takes a string as input and reverse only the vowels of a string. Example 1:Giv ...

  8. [LeetCode] Reverse String 翻转字符串

    Write a function that takes a string as input and returns the string reversed. Example: Given s = &q ...

  9. [LeetCode] Flip Game 翻转游戏

    You are playing the following Flip Game with your friend: Given a string that contains only these tw ...

随机推荐

  1. $.getJSON异步请求和同步请求

    先说一下我遇到的问题吧,我之前的一个函数想调用上一个函数的返回值,但是它的返回值一直为空,后来翻了一些资料才明白是异步请求在作怪,不多说,看例子,这是我之前有返回值函数的代码: function ge ...

  2. Openssl生成根证书、服务器证书并签核证书

    1.修改Openssl配置文件CA目录: cat /etc/pki/tls/openssl.cnf dir = /etc/pki/CA 2.生成根证书及私钥: #http://www.haiyun.m ...

  3. 经过本人 6 年.net 工作经验证明 .net 工资确实比 Java 低

    很久没有逛博客园了,很久没有出来吐槽了.怎么呢?生活压力大,就需要找地方吐槽. 排版不怎么好,文笔不怎么好,可以看出我不是雇佣的写手. 工作到今夏,已经有6个年头了,一直使用着.net技术,但是最近工 ...

  4. paper 68 :MATLAB中取整函数(fix, floor, ceil, round)的使用

    MATLAB取整函数 1)fix(x) : 截尾取整. >> fix( [3.12 -3.12]) ans =      3    -3 (2)floor(x):不超过x 的最大整数.(高 ...

  5. 阿里 drds 分布式数据库分节点查询

    mybatis 模式下,xml 中写法 <select id="selectFailDetailOneNode" resultMap="BaseResultMap& ...

  6. 一个noconsole程序

    貌似是一个外国人写的,作用应该是让控制台的程序运行的时候不会弹出那个控制台黑框.想用来让它不显示 php-cgi.exe 运行后的窗口,可是效果不是预期的. 项目在 github 的位置:https: ...

  7. keep your work after network broken

    如下设置可以保证在网络中断后tso仍然可以继续active,并等到下一次reconnect sys1.tcpparms(tnprof7d) -- Dataset name and PDS name b ...

  8. BPM 应用系统开发案例实战

    概述 IBM BPM 的前身是 Lombardi,是由 IBM 于 2009 年收购的产品,之后产品更名为 IBM WebSphere Lombardi Edition,目前最新版本称为 IBM BP ...

  9. opencv常用数据结构之:IplImage

    typedef struct_IplImage{      int nSize; //IplImage大小      int ID; //版本(=0)      int nChannels; //大多 ...

  10. 50136142WXY的百度地图

    50136142WXY的百度地图 [试题描述] 社团里的WXY童鞋今天要出去旅游啦(他现在在北京为1号城市),决定去朝鲜平壤(N号城市).但是很穷的WXY没有钱坐飞机,只好坐汽车去朝鲜了.但是车上的百 ...