iOS开发CoreGraphics核心图形框架之四——变换函数
一、引言
在上一篇博客中,介绍了有关CGContext相关操作方法,其中可以直接调用一些方法来进行所绘制图形的平移,缩放,翻转等变换。对于图形了几何变换,开发者也可以采用另一种方式实现,CoreGraphics框架中提供了CGAffineTransform结构体,这个结构体中定义了图形变换的相关信息。
关于CGContext的相关内如博地址客如下:https://my.oschina.net/u/2340880/blog/759070。
CGAffineTransform中定义的方法即意义列举如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| CGAffineTransform CGAffineTransformIdentity;
CGAffineTransform CGAffineTransformMake(CGFloat a, CGFloat b, CGFloat c, CGFloat d, CGFloat tx, CGFloat ty);
CGAffineTransform CGAffineTransformMakeTranslation(CGFloat tx, CGFloat ty);
CGAffineTransform CGAffineTransformMakeScale(CGFloat sx, CGFloat sy);
CGAffineTransform CGAffineTransformMakeRotation(CGFloat angle);
bool CGAffineTransformIsIdentity(CGAffineTransform t);
CGAffineTransform CGAffineTransformTranslate(CGAffineTransform t, CGFloat tx, CGFloat ty);
CGAffineTransform CGAffineTransformScale(CGAffineTransform t, CGFloat sx, CGFloat sy);
CGAffineTransform CGAffineTransformRotate(CGAffineTransform t, CGFloat angle);
CGAffineTransform CGAffineTransformInvert(CGAffineTransform t);
CGAffineTransform CGAffineTransformConcat(CGAffineTransform t1, CGAffineTransform t2);
bool CGAffineTransformEqualToTransform(CGAffineTransform t1, CGAffineTransform t2);
CGPoint CGPointApplyAffineTransform(CGPoint point, CGAffineTransform t);
CGSize CGSizeApplyAffineTransform(CGSize size, CGAffineTransform t);
CGRect CGRectApplyAffineTransform(CGRect rect, CGAffineTransform t);
|
上述变换方法可以直接作用于View,示例如下:
1 2 3 4 5 6 7 8
| - (void)viewDidLoad { [super viewDidLoad]; UIImageView * view = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)]; view.backgroundColor =[UIColor whiteColor]; view.image = [UIImage imageNamed:@"image"]; view.transform = CGAffineTransformRotate(CGAffineTransformIdentity, M_PI_4); [self.view addSubview:view]; }
|
专注技术,热爱生活,交流技术,也做朋友。
——珲少 QQ群:203317592