标签:
//
// ViewController.m
// Transform演练
//
#import "ViewController.h"
typedef enum
{
kMovingDirTop = 10,
kMovingDirBottom,
kMovingDirLeft,
kMovingDirRight
} kMovingDir;
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIButton *headImageView;
// @property (nonatomic, assign) int delta;
@end
@implementation ViewController
/**
transform属性
在开发中如果遇到移动空间位置、改变大小最好使用transform属性
使用transform属性修改控件的位置、尺寸不需要计算形变之后的结果
*/
- (IBAction)move:(UIButton *)button
{
// self.delta -= 20;
// NSLog(@"%d",self.delta);
// MakeTranslation 是基于对象初始位置做的形变
// self.headImageView.transform = CGAffineTransformMakeTranslation(0, self.delta);
// Translate 是基于transform参数做的形变,实际效果就是一个累加的位移效果
switch (button.tag) {
case kMovingDirTop:
self.headImageView.transform = CGAffineTransformTranslate(self.headImageView.transform, 0, -20);
break;
case kMovingDirBottom:
self.headImageView.transform = CGAffineTransformTranslate(self.headImageView.transform, 0, +20);
break;
case kMovingDirLeft:
self.headImageView.transform = CGAffineTransformTranslate(self.headImageView.transform, -20, 0);
break;
case kMovingDirRight:
self.headImageView.transform = CGAffineTransformTranslate(self.headImageView.transform, +20, 0);
break;
}
}
- (IBAction)zoom:(UIButton *)button
{
if(button.tag){
self.headImageView.transform = CGAffineTransformScale(self.headImageView.transform, 1.2, 1.2);
} else {
self.headImageView.transform = CGAffineTransformScale(self.headImageView.transform, 0.8, 0.8);
}
}
- (IBAction)rotate:(UIButton *)button
{
// 提示:在OC中,所有跟角度相关的数值,都是弧度值 M_PI = 180度
// 正数顺时针旋转
// 负数逆时针旋转
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2];
if (button.tag) {
self.headImageView.transform = CGAffineTransformRotate(self.headImageView.transform, -M_PI_4);
} else {
self.headImageView.transform = CGAffineTransformRotate(self.headImageView.transform, M_PI_4);
}
[UIView commitAnimations];
}
@end
标签:
原文地址:http://www.cnblogs.com/Holy-Mac/p/4277733.html