transform的簡(jiǎn)單使用
程序一開(kāi)始顯示圖片:
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageV;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
// 上移
- (IBAction)moveUp:(id)sender {
//平移
[UIView animateWithDuration:0.5 animations:^{
// 使用Make,它是相對(duì)于最原始的位置做的形變,開(kāi)發(fā)中画切,不用這個(gè)己单,只能移動(dòng)一次,
// 看見(jiàn)有Make,就只能移動(dòng)一次浪耘,
// self.imageV.transform = CGAffineTransformMakeTranslation(0, -50);
// 相對(duì)于上一次做形變罢洲,開(kāi)發(fā)中經(jīng)常使用下面的
self.imageV.transform = CGAffineTransformTranslate(self.imageV.transform, 0, -50);
}];
}
// 下移
- (IBAction)moveDown:(id)sender {
//平移
[UIView animateWithDuration:0.5 animations:^{
//使用Make,它是相對(duì)于最原始的位置做的形變.
//self.imageV.transform = CGAffineTransformMakeTranslation(0, 50);
//相對(duì)于上一次做形變.
self.imageV.transform = CGAffineTransformTranslate(self.imageV.transform, 0, 50);
}];
}
// 旋轉(zhuǎn)
- (IBAction)rotation:(id)sender {
[UIView animateWithDuration:0.5 animations:^{
//旋轉(zhuǎn)(旋轉(zhuǎn)的度數(shù), 是一個(gè)弧度)
//self.imageV.transform = CGAffineTransformMakeRotation(M_PI_4);
self.imageV.transform = CGAffineTransformRotate(self.imageV.transform, M_PI_4);
}];
}
// 縮放
- (IBAction)scale:(id)sender {
[UIView animateWithDuration:0.5 animations:^{
//縮放
//self.imageV.transform = CGAffineTransformMakeScale(0.5, 0.5);
self.imageV.transform = CGAffineTransformScale(self.imageV.transform, 0.8, 0.8);
}];
}
@end
上移效果圖片:
下移效果圖片:
旋轉(zhuǎn)效果圖片:
縮放效果圖片: