IF U WANT SOME

仿射变换本质是一种矩阵变换,可以用来做平移,缩放,旋转等操作

这些操作我们可以包装到动画中去

1.apple的官方文档定义:

CGAffineTransform CGAffineTransformMake ( CGFloat a, CGFloat b, CGFloat c, CGFloat d, CGFloat tx, CGFloat ty );ParametersaThe value at position [1,1] in the matrix.bThe value at position [1,2] in the matrix.cThe value at position [2,1] in the matrix.dThe value at position [2,2] in the matrix.txThe value at position [3,1] in the matrix.tyThe value at position [3,2] in the matrix.

(a,b,c,d,tx,ty)是一个transform的构成,包含下面的这6个数

tx,ty实际上在视图中是视图的位置,我们可以改变之来做平移操作

对应的矩阵表视图如下:

2.创建transform的几种方式

通过

CGAffineTransformMake(原生矩阵)CGAffineTransformMakeRotation (旋转)CGAffineTransformMakeScale(缩放)CGAffineTransformMakeTranslation(平移)

这几个方法可以创建一个 仿射变换

3.改变transform的几种方式

通过

(1)在原来的transform基础上再进行一下平移操作,返回值为新的transform

CGAffineTransformTranslate ( CGAffineTransform t, CGFloat tx, CGFloat ty );ParameterstAn existing affine transform.txThe value by which to move x values with the affine transform.tyThe value by which to move y values with the affine transform.Return ValueA new affine transformation matrix.(2)在原来的基础上进行缩放,返回一个新的transformCGAffineTransformScale ( CGAffineTransform t, CGFloat sx, CGFloat sy );ParameterstAn existing affine transform.sxThe value by which to scale x values of the affine transform.syThe value by which to scale y values of the affine transform.(3)在原来的基础上旋转,注意旋转的角度是弧度值CGAffineTransformRotate ( CGAffineTransform t, CGFloat angle );ParameterstAn existing affine transform.angleThe angle, in radians, by which to rotate the affine transform. In iOS, a positive value specifies counterclockwise rotation and a negative value specifies clockwise rotation. In OS X, a positive value specifies clockwise rotation and a negative value specifies counterclockwise rotation.(4)反转之前的transform(逆操作)CGAffineTransformInvert ( CGAffineTransform t );ParameterstAn existing affine transform.Return ValueA new affine transformation matrix. If the affine transform passed in parameter t cannot be inverted, Quartz returns the affine transform unchanged.(5)合并两个transform,把两个transform合并在一起CGAffineTransformConcat ( CGAffineTransform t1, CGAffineTransform t2 );Parameterst1The first affine transform.t2The second affine transform. This affine transform is concatenated to the first affine transform.Return ValueA new affine transformation matrix. That is, t’ = t1*t2.4.应用transform,例如CGPoint,CGSize,CGRect可以直接应用这个transform来进行相应的矩阵操作(1)CGPointApplyAffineTransform (CGPoint point,CGAffineTransform t );(可以获得仿射变换之后的点..下类似)ParameterspointA point that specifies the x- and y-coordinates to transform.tThe affine transform to apply.Return ValueA new point resulting from applying the specified affine transform to the existing point.(2)CGSizeApplyAffineTransform (CGSize size,CGAffineTransform t );ParameterssizeA size that specifies the height and width to transform.tThe affine transform to apply.Return ValueA new size resulting from applying the specified affine transform to the existing size.(3)CGRectApplyAffineTransform ( CGRect rect,CGAffineTransform t );ParametersrectThe rectangle whose corner points you want to transform.tThe affine transform to apply to the rect parameter.Return ValueThe transformed rectangle.

示例,把一个点进行平移运算,得到一个新的点

CGPoint pp = CGPointMake(100, 100);CGAffineTransform pingyi = CGAffineTransformMakeTranslation(100, 0);CGPoint newPP = CGPointApplyAffineTransform(pp, pingyi);//对一个点做仿射变换NSLog(@"平移之后的点 坐标是 %@", NSStringFromCGPoint(newPP));5.评判transformbool CGAffineTransformIsIdentity ( CGAffineTransform t );ParameterstThe affine transform to check.Return ValueReturns true if t is the identity transform, false otherwise.(1)检测一个Transform是不是恒等变换,,也就是说不变bool CGAffineTransformEqualToTransform ( CGAffineTransform t1, CGAffineTransform t2 );Parameterst1An affine transform.t2An affine transform.Return ValueReturns true if t1 and t2 are equal, false otherwise.(2)比较两个transform是否相等6.transform动画

设置号一个transform之后剩下的事就是加入到UIView动画里面去执行了

CGAffineTransform tt = CGAffineTransformMakeScale(0.5, 0.5);[UIView animateWithDuration:1 animations:^{view1.transform = tt;}];我们需要使用UIView的transform属性其他的操作类似,当然我们也可以组合这些transform()CGAffineTransformConcat使用上面的方法可以合并两个transform

更多文章:

是会眨眼的星星,而当火车弯曲而行,这些星群便上上下下的画着弧线,

IF U WANT SOME

相关文章:

你感兴趣的文章:

标签云: