- (void)viewDidLoad {
[super viewDidLoad];
UILabel *backLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 100, 100)];
backLabel.backgroundColor = [UIColor blueColor];
backLabel.textColor = [UIColor whiteColor];
backLabel.text = @"原效果图";
[self.view addSubview:backLabel];
[self CGAffineTransformMakeScaleTest];
[self CGAffineTransformMakeRotationTest];
[self CGAffineTransformMakeTranslationTest];
[self CGAffineTransformMakeTestOne];
[self CGAffineTransformMakeTestTwo];
}
/**
缩放: CGAffineTransformMakeScale(<#CGFloat sx#>, <#CGFloat sy#>)
会按照中心点 位置 进行缩放操作
CGPoint centerpoint = CGPointMake(backView.frame.origin.x + backView.frame.size.width, backView.frame.origin.y+backView.frame.size.height);
*/
- (void)CGAffineTransformMakeScaleTest
{
UILabel *backView = [[UILabel alloc] initWithFrame:CGRectMake(150, 80, 100, 100)];
backView.backgroundColor = [UIColor redColor];
backView.text = @"进行缩放操作";
backView.textColor = [UIColor whiteColor];
[self.view addSubview:backView];
backView.transform = CGAffineTransformMakeScale(0.1, 0.1);
[UIView animateWithDuration:5.0f animations:^{
backView.transform = CGAffineTransformMakeScale(1.0, 1.0f);
} completion:^(BOOL finished) {
backView.transform = CGAffineTransformIdentity;
}];
}
/**
旋转: CGAffineTransformMakeRotation(<#CGFloat angle#>)
会按照中心点 位置 进行旋转操作
M_PI =180;
CGPoint centerpoint = CGPointMake(backView.frame.origin.x + backView.frame.size.width, backView.frame.origin.y+backView.frame.size.height);
*/
- (void)CGAffineTransformMakeRotationTest
{
UILabel *backView = [[UILabel alloc] initWithFrame:CGRectMake(50, 200, 100, 100)];
backView.backgroundColor = [UIColor grayColor];
backView.text = @"进行旋转";
backView.textColor = [UIColor whiteColor];
[self.view addSubview:backView];
backView.transform = CGAffineTransformMakeRotation(0);
[UIView animateWithDuration:5.0f animations:^{
backView.transform = CGAffineTransformMakeRotation(M_PI/4);
} completion:^(BOOL finished) {
}];
}
/**
平移操作
现对于控件frame 进行左边 偏移x距离
CGAffineTransformMakeTranslation(<#CGFloat tx#>, <#CGFloat ty#>)
现对于控件frame 进行下边 偏移y距离
*/
- (void)CGAffineTransformMakeTranslationTest
{
UILabel *backView = [[UILabel alloc] initWithFrame:CGRectMake(180, 250, 100, 100)];
backView.backgroundColor = [UIColor cyanColor];
backView.text = @"进行平移";
backView.textColor = [UIColor whiteColor];
[self.view addSubview:backView];
[UIView animateWithDuration:5.0f animations:^{
backView.transform = CGAffineTransformMakeTranslation(50, 0);
} completion:^(BOOL finished) {
[UIView animateWithDuration:5.0f animations:^{
backView.transform = CGAffineTransformMakeTranslation(50, 50);
} completion:^(BOOL finished) {
}];
}];
}
/**
进行一系列动作。包括 缩放 旋转 平移
CGAffineTransformMake(a, b, c, d,tx, ty);
ad 缩放
bc 旋转
xy 平移
tx 用来控制在x轴方向上的平移
ty 用来控制在y轴方向上的平移
a 用来控制在x轴方向上的缩放
d 用来控制在y轴方向上的缩放
abcd 共同控制旋转
*/
- (void)CGAffineTransformMakeTestOne
{
UILabel *backView = [[UILabel alloc] initWithFrame:CGRectMake(0, 400, 100, 100)];
backView.backgroundColor = [UIColor orangeColor];
backView.text = @"进行动画组合(缩放 + 平移)";
backView.textColor = [UIColor whiteColor];
backView.numberOfLines = 0;
backView.font = [UIFont systemFontOfSize:10];
[self.view addSubview:backView];
CGFloat offsetX = backView.frame.size.width/2;
CGFloat offsetY = -backView.frame.size.height/2;//中心点位置开始centerpoint
[UIView animateWithDuration:5.0f animations:^{
backView.transform = CGAffineTransformMake(0.01, 0, 0, 0.01, offsetX, offsetY);
} completion:^(BOOL finished) {
backView.transform = CGAffineTransformMake(1, 0, 0, 1, 0, 0);
}];
}
- (void)CGAffineTransformMakeTestTwo
{
UILabel *backView = [[UILabel alloc] initWithFrame:CGRectMake(200, 450, 100, 100)];
backView.backgroundColor = [UIColor greenColor];
backView.text = @"进行动画组合(旋转 +平移)";
backView.textColor = [UIColor whiteColor];
backView.numberOfLines = 0;
backView.font = [UIFont systemFontOfSize:10];
[self.view addSubview:backView];
CGFloat offsetX = backView.frame.size.width/2;
CGFloat offsetY = -backView.frame.size.height/2;//中心点位置开始centerpoint
[UIView animateWithDuration:5.0f animations:^{
backView.transform = CGAffineTransformMake(0, 0.1, 0.1, 0, offsetX, offsetY);
} completion:^(BOOL finished) {
backView.transform = CGAffineTransformMake(0, 1, 1, 0, 0, 0);
}];
}