IOS之UI button的縮放旋轉平移
阿新 • • 發佈:2021-01-31
IOS 之UI按鈕的縮放的旋轉和平移
//
// ViewController.m
// 02-transform屬性的介紹
//
// Created by 魯軍 on 2021/1/30.
//
#import "ViewController.h"
@interface ViewController ()
- (IBAction)move;
- (IBAction)rotate;
- (IBAction)scale;
@property (weak, nonatomic) IBOutlet UIButton *btnIcon;
- (IBAction)clear;
@property (weak, nonatomic) IBOutlet UITextField *txt1;
- (IBAction)test;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (IBAction)scale {
// self.btnIcon.transform = CGAffineTransformMakeScale(0.5,0.5);
self.btnIcon. transform = CGAffineTransformScale(self.btnIcon.transform, 1.5, 1.5);
}
- (IBAction)rotate {
// self.btnIcon.transform = CGAffineTransformMakeRotation(-M_PI_4);
// self.btnIcon.transform = CGAffineTransformRotate(self.btnIcon.transform, -M_PI_4);
[UIView animateWithDuration:2.5 animations:^{
self.btnIcon.transform = CGAffineTransformRotate(self.btnIcon.transform, -M_PI_4);
self.btnIcon.transform = CGAffineTransformTranslate(self.btnIcon.transform, 0, 50);
self.btnIcon.transform = CGAffineTransformScale(self.btnIcon.transform, 1.5, 1.5);
}];
}
- (IBAction)move {
// 下面這句話的意思是 告訴控制元件。平移到距離原始位置-50 的位置
//self.btnIcon.transform = CGAffineTransformMakeTranslation(0, -50);
// 基於 一箇舊的值 在進行平移
// 基於現有的一個值。再進行平移
self.btnIcon.transform = CGAffineTransformTranslate(self.btnIcon.transform, 0, 50);
}
- (IBAction)clear {
self.btnIcon.transform = CGAffineTransformIdentity;
}
- (IBAction)test {
// for (UIView *view in self.view.subviews) {
// view.backgroundColor=[UIColor redColor];
// }
//self.txt1.superview.backgroundColor=[UIColor yellowColor];
//
// UITextField *txt = (UITextField *)[self.view viewWithTag:110];
// txt.text = @"大軍";
while(self.view.subviews.firstObject){
[self.view.subviews.firstObject
removeFromSuperview];
}
}
@end