CGAffineTransformMakeTranslation和CGAffineTransformTranslate、CGAffineTransformMakeScale和CGAffineTransformScale、还有CGAffineTransformMakeRotation和CGAffineTransformRotation,这个是标题就是太长了。
细心的小伙伴发现,他们之间的关系就是多了一个make,那我们会猜,他们功能会不会有相似......
恭喜答对了。
我们举例说明一下:
如果一个
UIButton *tmpBtn1 = [[UIButton alloc] initWithFrame:CGRectMake(0, 200, 120, 40)];
这里主要看tmpBtn1的frame位置是(0,200),那它的center是(60,220),这时(这个tmpBtn1已经被你addSubview了)我们执行一下:
tmpBtn1.transform = CGAffineTransformMakeTranslation(160, 0);
小伙伴们注意了这里有个(160,0),它是一个向量(大家应该知道向量吧),换句话说,在调用CGAffineTransformMakeTranslation(x,y)的时候,已经把(60,220)作为(绝对)原点,那么移动后终点应该是(220,220),大家算出来了吗?这时候tmpBtn1的frame为(160,200,120,40)。
少一个Make,CGAffineTransformMakeTranslation(x,y)变成CGAffineTransformTranslation(trans,x,y),多了一个参数其实都一样,为什么这么说,CGAffineTransformTranslation(trans,x,y)中的trans是给这个方法指定了一个相对原点,比如这样调用:
UIButton *tmpBtn2 = [[UIButton alloc] initWithFrame:CGRectMake(0, 200, 120, 40)];
tmpBtn2.transform = CGAffineTransformTranslation(CGAffineTransformMakeTranslation(160, 0),20,0),
tmpBtn2先移动向量(160,0),在移动(20,0)。
所以CGAffineTransformTranslation(CGAffineTransformMakeTranslation(160, 0),20,0) == CGAffineTransformMakeTranslation(180, 0) 是ture的。
同理可以的出来CGAffineTransformMakeScale和CGAffineTransformScale、还有CGAffineTransformMakeRotation和CGAffineTransformRotation是一样的道理。
UIButton *tmpBtn3 = [[UIButton alloc] initWithFrame:CGRectMake(0, 200, 120, 40)];
tmpBtn3.transform = CGAffineTransformMakeScale(2,2); 大小变成 240*80
UIButton *tmpBtn4 = [[UIButton alloc] initWithFrame:CGRectMake(0, 200, 120, 40)];
tmpBtn4.transform = CGAffineTransformScale(CGAffineTransformMakeScale(2,2),2,2);
tmpBtn4认为(2,2)的frame大小(即240*80),是放大倍数的标准,所以就会放大4倍。
有错误的地方请大家留言指正。
对了CGAffineTransformMake这个更牛掰(a,b,c,d,x,y)6个参数就把旋转、缩放、移位放到一起。
摘自:http://m.blog.csdn.net/blog/yhc13429826359/34467781