<span style="font-family:Verdana;"><span style="font-family:Microsoft YaHei;"><span style="font-family:Microsoft YaHei;">#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIButton *moving;
- (IBAction)move;
- (IBAction)rotate;
- (IBAction)scale;
- (IBAction)goback;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)move {
// 2.修改结构体值
// 下面这句话的意思是:告诉控件,要平移到距离原始位置-50的位置
// self.moving.transform = CGAffineTransformMakeTranslation(0, 50); // 向上平移
// 基于一个旧的值,再进行平移
// 基于一个现有的值,再进行平移
self.moving.transform = CGAffineTransformTranslate(self.moving.transform, 0, 50);
}
- (IBAction)rotate {
//45°
// self.moving.transform = CGAffineTransformMakeRotation(M_PI_4);
self.moving.transform = CGAffineTransformRotate(self.moving.transform, M_PI_4);
}
- (IBAction)scale {
// self.moving.transform = CGAffineTransformMakeScale(0.5, 0.5);
[UIView animateWithDuration:2.5 animations:^{
self.moving.transform = CGAffineTransformTranslate(self.moving.transform, 0, 50);
self.moving.transform = CGAffineTransformRotate(self.moving.transform, M_PI_4);
self.moving.transform = CGAffineTransformScale(self.moving.transform, 1.5, 1.5);
}];
}
//让控件回到原来的位置
- (IBAction)goback {
self.moving.transform = CGAffineTransformIdentity;
}
@end
</span></span></span>