tag 和transform属性
1.tag 标签,就相当于身份识别的标码,可以通过tag值获取对应的对象。
2.使用transform 实现对象的平移和旋转。
1 // 2 // ViewController.m 3 // 04-transform 使用 4 // 5 // Created by Stephen on 16/4/12. 6 // Copyright © 2016年 Stephen. All rights reserved. 7 // 8 9 #import "ViewController.h" 10 11 @interface ViewController () 12 13 - (IBAction)up; 14 15 //@property (weak, nonatomic) IBOutlet UIButton *head; 16 - (IBAction)rotate; 17 18 @end 19 20 @implementation ViewController 21 22 - (IBAction)up { 23 //1.取得图像按钮 24 UIButton *head = (UIButton *)[self.view viewWithTag:10]; 25 //2. 26 // head.transform = CGAffineTransformMakeTranslation(0, -20); // 永远只对原点进行20单位的位移 27 28 //叠加位移 29 head.transform = CGAffineTransformTranslate(head.transform, 0, -20); //每次都是进行20的位移 30 31 32 } 33 - (IBAction)rotate 34 { 35 UIButton *head = (UIButton *)[self.view viewWithTag:10]; 36 37 // head.transform = CGAffineTransformMakeRotation(M_PI_4); 38 39 head.transform =CGAffineTransformRotate(head.transform, M_PI_4); 40 } 41 @end