平移缩放旋转,根据对象的transform属性来操作的
方法名里有make,都是基于原来的初始对象,只能点击一次。
方法名里没有make,第一个参数是自身的transform属性,都是基于上一次的,可以多次点击
然后负值分别就是代表反方向,缩放,逆时针。
缩放值代表的是系数,例如都是1,代表XY长短 都不变。而且缩放是以中心点为基准
M_PI代表180度,代码中输入M_PI,点进去看下会发现有更多相关度数的定义。
#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 */
1 - (void)viewDidLoad { 2 [super viewDidLoad]; 3 // Do any additional setup after loading the view. 4 [self setBaseUI]; 5 // self.view.backgroundColor=[UIColor redColor]; 6 7 } 8 -(void)setBaseUI{ 9 [self transBtn]; 10 [self imageView]; 11 12 } 13 -(UIButton *)transBtn{ 14 if(!_transBtn) 15 { 16 _transBtn=[UIButton buttonWithType:UIButtonTypeCustom]; 17 _transBtn.frame=CGRectMake(60, 60, 100, 40); 18 [_transBtn setTitle:@"点击" forState:UIControlStateNormal]; 19 [_transBtn setTitle:@"点击" forState:UIControlStateHighlighted]; 20 _transBtn.backgroundColor=[UIColor grayColor]; 21 [_transBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; 22 [_transBtn setTitleColor:[UIColor blueColor] forState:UIControlStateHighlighted]; 23 24 [_transBtn addTarget:self action:@selector(transBtnClick) forControlEvents:UIControlEventTouchUpInside]; 25 [self.view addSubview:_transBtn]; 26 } 27 return _transBtn; 28 } 29 -(void)transBtnClick{ 30 //平移,在XY轴都平移对应的量。 31 // self.imageView.transform=CGAffineTransformMakeTranslation(60, 60); 32 // NSLog(@"===%f--%f",_imageView.frame.origin.x,_imageView.frame.origin.y); 33 //平移,可累加,可多次点击,每次点击都是在上一次的位置上 34 // self.imageView.transform=CGAffineTransformTranslate(_imageView.transform, 10, 10); 35 // NSLog(@"===%f--%f",_imageView.frame.origin.x,_imageView.frame.origin.y); 36 //缩放,可累加 37 // self.imageView.transform=CGAffineTransformScale(_imageView.transform, -0.8, -0.8); 38 // NSLog(@"===%f--%f",_imageView.frame.origin.x,_imageView.frame.origin.y); 39 //旋转 40 self.imageView.transform=CGAffineTransformRotate(_imageView.transform, M_PI_4); 41 42 } 43 -(UIImageView *)imageView{ 44 if(!_imageView) 45 { //中心110,170 46 _imageView=[[UIImageView alloc]initWithFrame:CGRectMake(60, 120, 100, 100)]; 47 _imageView.image=[UIImage imageNamed:@"1.png"]; 48 _imageView.backgroundColor=[UIColor redColor]; 49 [self.view addSubview:_imageView]; 50 51 } 52 return _imageView; 53 54 }