2023年7月13日发(作者:)
仿射变换---位移+缩放⽐例+旋转对于仿射变换的理解,以本⼈现阶段⽔平还谈不上是深⼊了解,我喜欢把它想象成⼀种简单的动画效果,下⾯介绍⼏种简单的变化:位置移动,按⼀定⽐例缩放,顺时针、逆时针旋转#import "ViewController.h"@interface ViewController ()@property (nonatomic,weak) UIView * rectView;@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad];
//"点我" 控制按钮 UIButton * button=[UIButton buttonWithType:UIButtonTypeCustom]; [button setTitle:@"点我" forState:UIControlStateNormal]; =CGRectMake(-110, 20, 100, 44); oundColor=[UIColor redColor]; //添加点击事件 [button addTarget:self action:@selector(clickMeAction) forControlEvents:UIControlEventTouchUpInside]; [ addSubview:button];
UIView * rectView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 150, 150)]; =; oundColor=[UIColor greenColor]; ew=rectView; [ addSubview:rectView];}#pragma mark - clickAction- (void) clickMeAction{//仿射变换移动 //1.从当前位置,向右移动50,向下移动100 (直接变换) /* orm=CGAffineTransformMakeTranslation(50, 100); */
//2.(⽅法⼀)从当前位置,向右移动50,向下移动100 (0.5秒钟时延) /* [UIView animateWithDuration:0.5 animations:^{ orm=CGAffineTransformMakeTranslation(50, 100); }]; */
//3.(⽅法⼆)从当前位置,向右移动50,向下移动100 (0.5秒钟时延) /* [UIView animateWithDuration:0.5 animations:^{ //orm=CGAffineTransformMakeTranslation(50, 100); orm=CGAffineTransformTranslate(orm, 100, 100); }]; */
//仿射变换⽐例 //1.中⼼点不变,宽度缩⼩为原来的0.1倍,⾼度缩短为原来的0.5倍 /* [UIView animateWithDuration:0.5 animations:^{ orm=CGAffineTransformMakeScale(0.1, 0.5); }]; */
//2.中⼼点不变,扩⼤为原来的5倍 /* [UIView animateWithDuration:0.5 animations:^{ orm=CGAffineTransformMakeScale(5, 5); }]; */
//3.(⽅法⼀)向右向下各移动100 /* [UIView animateWithDuration:0.5 animations:^{ orm=CGAffineTransformMakeTranslation(100, 100); }]; */
//4.(⽅法⼆)向右向下各移动100 /* [UIView animateWithDuration:0.5 animations:^{ orm=CGAffineTransformMakeTranslation(100, 100); }]; */
//5.在前⼀个位置的基础之上,向右向下分别移动1个距离 /* [UIView animateWithDuration:0.5 animations:^{ orm=CGAffineTransformTranslate(orm,1,1); }]; */
//6.在前⼀个位置的基础之上,向右向下分别移动100个距离 /* [UIView animateWithDuration:0.5 animations:^{ CGAffineTransform form=orm; orm=CGAffineTransformTranslate(form,100,100); }]; */
//7.来回弹跳切换着向右下⾓移动10个单位 /* [UIView animateWithDuration:0.5 animations:^{ CGAffineTransform form=orm; orm=CGAffineTransformMakeScale(2, 2); orm=CGAffineTransformTranslate(form,10,10); }]; */
//仿射变换---旋转 //1.顺时针旋转90度 /* [UIView animateWithDuration:0.5 animations:^{ orm=CGAffineTransformMakeRotation(M_PI_2); }]; */
//2.在前⼀个位置的基础之上,顺时针旋转45度 /* [UIView animateWithDuration:0.5 animations:^{ CGAffineTransform form=orm; orm=CGAffineTransformRotate(form,M_PI_4); }]; */
//3.在前⼀个位置的基础之上,逆时针旋转45度 /* [UIView animateWithDuration:0.5 animations:^{ CGAffineTransform form=orm;
orm=CGAffineTransformRotate(form,-M_PI_4); }]; */
//4.在前⼀个位置的基础之上,顺时针旋转确定的度数 [UIView animateWithDuration:0.5 animations:^{ CGAffineTransform form=orm;
orm=CGAffineTransformRotate(form,9/100.0*M_PI); }];
}@end
发布者:admin,转转请注明出处:http://www.yc00.com/xiaochengxu/1689261329a226269.html
评论列表(0条)