#import "ViewController.h"
@interface ViewController ()
- (IBAction)move:(UIButton *)sender;
- (IBAction)zoom:(UIButton *)sender;
- (IBAction)rotate:(UIButton *)sender;
@end
@implementation ViewController
// 移动
- (IBAction)move:(UIButton *)sender {
UIButton *img = (UIButton *)[self.view viewWithTag:10];
switch (sender.tag){
case 1: // 上
img.transform = CGAffineTransformTranslate(img.transform, 0, -10);
break;
case 2: // 下
img.transform = CGAffineTransformTranslate(img.transform, 0, 10);
break;
case 3: // 左
img.transform = CGAffineTransformTranslate(img.transform, -10, 0);
break;
case 4: // 右
img.transform = CGAffineTransformTranslate(img.transform, 10, 0);
break;
}
}
// 缩放
- (IBAction)zoom:(UIButton *)sender {
UIButton *img = (UIButton *)[self.view viewWithTag:10];
switch (sender.tag){
case 5: // 放大
img.transform = CGAffineTransformScale(img.transform, 1.2, 1.2);
break;
case 6: // 缩小
img.transform = CGAffineTransformScale(img.transform, 0.8, 0.8);
break;
}
}
#pragma mark 旋转
- (IBAction)rotate:(UIButton *)sender {
UIButton *img = (UIButton *)[self.view viewWithTag:10];
switch (sender.tag){
case 7: // 左旋转
img.transform = CGAffineTransformRotate(img.transform, -0.25);
break;
case 8: // 右旋转
img.transform = CGAffineTransformRotate(img.transform, 0.25);
break;
}
}
@end