self.view.ios view transformm=CGAffineios view transformmIdentity 为什么要这么用

CGAffineTransform相关函数
博客分类:&
CGAffineTransform rotation =
CGAffineTransformMakeRotation(M_PI_2);
[xxx setTransform:rotation];
呵呵就这么简单的两行代码就可以实现了!
顺便记录一些常量,以后用的着!
#define M_E&&&&&&&&&2.&&&e
#define M_LOG2E&&&&&1.&&&log
#define M_LOG10E&&&&0.&&log
#define M_LN2&&&&&&&0.&&log
#define M_LN10&&&&&&2.&&&log
#define M_PI&&&&&&&&3.&&&pi
#define M_PI_2&&&&&&1.&&&pi/2
#define M_PI_4&&&&&&0.&&pi/4
#define M_1_PI&&&&&&0.&&1/pi
#define M_2_PI&&&&&&0.&&2/pi
#define M_2_SQRTPI&&1.&&&2/sqrt(pi)
#define M_SQRT2&&&&&1.&&&sqrt(2)
#define M_SQRT1_2&&&0.&&1/sqrt(2)
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,
static inline double radians
(double degrees) {return degrees * M_PI/180;}
CGContextRotateCTM (myContext,
radians(&45.));
CGContextScaleCTM (myContext, .5,
两种转换合成后的效果,先把图片移动到右上角,然后旋转180度
CGContextTranslateCTM (myContext,
CGContextRotateCTM (myContext,
radians(-180.));
组合几个动作
CGContextTranslateCTM (myContext,
CGContextScaleCTM (myContext, .25,
CGContextRotateCTM (myContext,
radians ( 22.));
CGContextRotateCTM (myContext,
radians ( 22.));
CGContextScaleCTM (myContext, .25,
CGContextTranslateCTM (myContext,
上面是通过直接修改当前的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是否相等
CGAffineTransformEqualToTransform (
&CGAffineTransform t1,
&CGAffineTransform t2
获得Affine Transform
CGAffineTransform
CGContextGetUserSpaceToDeviceSpaceTransform (
&CGContextRef c
下面的函数只起到查看的效果,比如看一下这个用户空间的点,转换到设备空间去坐标是多少
CGContextConvertPointToDeviceSpace (
&CGContextRef c,
&CGPoint point
CGContextConvertPointToUserSpace (
&CGContextRef c,
&CGPoint point
CGContextConvertSizeToDeviceSpace (
&CGContextRef c,
&CGSize size
CGContextConvertSizeToUserSpace (
&CGContextRef c,
&CGSize size
CGContextConvertRectToDeviceSpace (
&CGContextRef c,
&CGRect rect
CGContextConvertRectToUserSpace (
&CGContextRef c,
&CGRect rect
CTM真正的数学行为
这个转换矩阵其实是一个 3x3的 举证
下面举例说明几个转换运算的数学实现
x y 是原先点的坐标
下面是从用户坐标转换到设备坐标的计算公式
下面是一个identity
matrix,就是输入什么坐标,出来什么坐标,没有转换
最终的计算结果是 x=x,y=y,
&可以用函数判断这个矩阵是不是一个
identity matrix
bool CGAffineTransformIsIdentity
&CGAffineTransform t
(void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
& duration:(NSTimeInterval)duration
(toInterfaceOrientation == UIInterfaceOrientationPortrait)
& self.view=
& self.view.transform =
CGAffineTransformIdentity;
& self.view.transform =
CGAffineTransformMakeRotation(degreesToRadian(0));
& self.view.bounds = CGRectMake(0.0, 0.0, 768.0,
& & & else if
(toInterfaceOrientation ==
UIInterfaceOrientationLandscapeLeft)
& self.view = self.
& self.view.transform =
CGAffineTransformIdentity;
& self.view.transform =
CGAffineTransformMakeRotation(degreesToRadian(-90));
& self.view.bounds = CGRectMake(0.0, 0.0, 1024.0,
& & & else if
(toInterfaceOrientation ==
UIInterfaceOrientationPortraitUpsideDown)
& self.view=
& self.view.transform =
CGAffineTransformIdentity;
& self.view.transform =
CGAffineTransformMakeRotation(degreesToRadian(180));
& self.view.bounds = CGRectMake(0.0, 0.0, 768.0,
& & & else if
(toInterfaceOrientation ==
UIInterfaceOrientationLandscapeRight)
& self.view = self.
& self.view.transform =
CGAffineTransformIdentity;
& self.view.transform =
CGAffineTransformMakeRotation(degreesToRadian(90));
& self.view.bounds = CGRectMake(0.0, 0.0, 1024.0,
Quartz转换实现的原理:Quartz把绘图分成两个部分,
&用户空间,即和设备无关,
&& &设备空间,
用户空间和设备空间中间存在一个转换矩阵 : CTM
本章实质是讲解CTM
Quartz提供的3大功能
移动,旋转,缩放
演示如下,首先加载一张图片
void CGContextDrawImage (
CGContextRef c,
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,
CGContextRotateCTM (myContext, radians ( 22.));
CGContextRotateCTM (myContext, radians ( 22.));
CGContextScaleCTM (myContext, .25,
CGContextTranslateCTM (myContext, w/4, 0);
上面是通过直接修改当前的ctm实现3大效果,下面是通过创建Affine Transforms,然后连接ctm实现同样的3种效果
这样做的好处是可以重用这个Affine Transforms
应用Affine Transforms 到ctm的函数
Creating Affine Transforms
CGAffineTransformMakeTranslation (
CGFloat tx,
CGFloat ty
CGAffineTransformTranslate (
CGFloat tx,
CGFloat ty
CGAffineTransformMakeRotation (
CGFloat angle
CGAffineTransformRotate (
CGFloat angle
CGAffineTransformMakeScale (
CGFloat sx,
CGFloat sy
CGAffineTransformScale (
CGFloat sx,
CGFloat sy
CGAffineTransformInvert (
只对局部产生效果
CGRectApplyAffineTransform (
判断两个AffineTrans是否相等
bool CGAffineTransformEqualToTransform (
获得Affine Transform
CGContextGetUserSpaceToDeviceSpaceTransform (
CGContextRef c
下面的函数只起到查看的效果,比如看一下这个用户空间的点,转换到设备空间去坐标是多少
CGContextConvertPointToDeviceSpace (
CGContextRef c,
CGContextConvertPointToUserSpace (
CGContextRef c,
CGContextConvertSizeToDeviceSpace (
CGContextRef c,
CGContextConvertSizeToUserSpace (
CGContextRef c,
CGContextConvertRectToDeviceSpace (
CGContextRef c,
CGContextConvertRectToUserSpace (
CGContextRef c,
CTM真正的数学行为
这个转换矩阵其实是一个 3x3的 举证
旋转加移动矩阵
bool CGAffineTransformIsIdentity (
下面举例说明几个转换运算的数学实现
x y 是原先点的坐标
下面是从用户坐标转换到设备坐标的计算公式
下面是一个identity
matrix,就是输入什么坐标,出来什么坐标,没有转换
最终的计算结果是 x=x,y=y,
&可以用函数判断这个矩阵是不是一个 identity matrix
void CGContextConcatCTM (
CGContextRef c,
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。self.view.transform=CGAffineTransformIdentity 为什么要这么用_百度知道下次自动登录
现在的位置:
& 综合 & 正文
关于IOS屏幕的旋转问题
处理IPhone屏幕的旋转是我们经常遇到的,当你做一个应用既然满足竖屏又要满足横屏,这就要求我们会处理屏幕旋转的问题!
方法一:自动布局
1.将项目中界面的四种手持方式都点上;
2.取消Use A
3.选择界面中某个控件然后到属性工具栏中去找到AutoSizing功能,勾选对应的绝对定位的线条
4.重写可以旋转的方法
-(BOOL)shouldAutorotate
return YES;
-(NSUInteger)supportedInterfaceOrientations
return UIInterfaceOrientationMaskA
方法二:手动布局一(通过改view种控件的坐标)
1.重写可以旋转的方法
-(BOOL)shouldAutorotate
return YES;
-(NSUInteger)supportedInterfaceOrientations
return UIInterfaceOrientationMaskA
2.勾选上项目中支持的四种手持类型
3.取消Use Autolayout
4.代码实现:
//每当屏幕旋转的时候都会触发一个
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
//如果是是横屏状态
if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft )
self.l1.frame = CGRectMake(20, 25, 110, 110);
self.l2.frame = CGRectMake(162, 25, 110, 110);
self.l3.frame = CGRectMake(304, 25, 110, 110);
self.r1.frame = CGRectMake(20, 178, 110, 110);
self.r2.frame = CGRectMake(162, 178, 110, 110);
self.r3.frame = CGRectMake(304, 178, 110, 110);}
方法三:手动布局二(在xib中新建一个支持横屏的view通过双view切换实现)
1.在xib文件中拖一个view控件,选择Orientation属性为横屏
2.布局好界面
3.将横纵view分别在controller.h文件中创建对应的属性,命名为
@property (retain,
nonatomic) IBOutlet UIView *landspaceV
@property (retain,
nonatomic) IBOutlet UIView *portatiorV
4.代码实现
宏定义实现角度转弧度
#define degreesToRadia(x) (M_PI * (x) / 180)//参数要加括号 ,尤其是参数附近特别要加括号
-(BOOL)shouldAutorotate
return YES;
-(NSUInteger)supportedInterfaceOrientations
return UIInterfaceOrientationMaskA
//每当屏幕旋转的时候都会触发一个
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
//如果是是横屏状态
if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft )
self.l1.frame = CGRectMake(20, 25, 110, 110);
self.l2.frame = CGRectMake(162, 25, 110, 110);
self.l3.frame = CGRectMake(304, 25, 110, 110);
self.r1.frame = CGRectMake(20, 178, 110, 110);
self.r2.frame = CGRectMake(162, 178, 110, 110);
self.r3.frame = CGRectMake(304, 178, 110, 110);
self.view = self.landspaceV
//self.view.transform = CGAffineTransformI
self.view.transform = CGAffineTransformMakeRotation(degreesToRadia(270));
self.view.bounds = CGRectMake(0, 0, 480, 300);
else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
self.l1.frame = CGRectMake(37, 20, 110, 110);
self.l2.frame = CGRectMake(37, 162, 110, 110);
self.l3.frame = CGRectMake(37, 304, 110, 110);
self.r1.frame = CGRectMake(190, 20, 110, 110);
self.r2.frame = CGRectMake(190, 162, 110, 110);
self.r3.frame = CGRectMake(190, 304, 110, 110);
self.view = self.landspaceV
//self.view.transform = CGAffineTransformI
self.view.transform = CGAffineTransformMakeRotation(degreesToRadia(90));
self.view.bounds = CGRectMake(0, 0, 480, 300);
else if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
self.view = self.portatiorV
self.view.transform = CGAffineTransformI
self.view.bounds = CGRectMake(0, 0, 320, 460);
else if(toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
self.view = self.portatiorV
//self.view = self.landspaceV
//self.view.transform = CGAffineTransformI
self.view.transform = CGAffineTransformMakeRotation(degreesToRadia(180));
self.view.bounds = CGRectMake(0, 0, 320, 460);
模拟屏幕旋转
commond + 方向键
&&&&推荐文章:
【上篇】【下篇】self.view.transform=CGAffineTransformIdentity 为什么要这么用_百度知道}

我要回帖

更多关于 cgaffinetransform 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信