您的位置:首页 > 产品设计 > UI/UE

UI 动画之反射变换的平移

2015-10-06 19:26 453 查看
@interface
ViewController ()

//准备一个用于动画的UIView

@property(nonatomic,strong)UILabel *customLabel;

//静止,用来对比

@property(nonatomic,strong)UIView *staticView;

@end

@implementation ViewController

- (void)viewDidLoad {

[superviewDidLoad];

//动画影响的属性:frame、center、bounds、background、alpha、transform、

//定义好自定义label

self.customLabel = [[UILabelalloc]initWithFrame:CGRectMake(0,0,
100,100)];

_customLabel.backgroundColor = [UIColormagentaColor];

_customLabel.center =self.view.center;

[self.viewaddSubview:_customLabel];

self.view.backgroundColor = [UIColorcyanColor];

//加一个可以对比的视图,可以直观的看出动画效果。

self.staticView = [[UIViewalloc]initWithFrame:CGRectMake(0,0,
100,100)];

_staticView.center =self.view.center;

_staticView.backgroundColor = [UIColorpurpleColor];

[self.viewinsertSubview:_staticViewbelowSubview:_customLabel];

}

#pragma mark 模拟
动画
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{

//开启动画之旅

[UILabelbeginAnimations:nilcontext:nil];

//之间就是定义动画

//切圆角

[_customLabel.layersetCornerRadius:50];

[_customLabel.layersetMasksToBounds:YES];

#pragma mark 平移

//三选一 :建议用第三种。

//在初始状态平移

//第一种:最繁琐
_customLabel.transform =CGAffineTransformMake(1,0,
0, 1,
34, 23);

//第二种,稍微好点

_customLabel.transform =CGAffineTransformMakeTranslation(50,50);

//第三种:灵活

//在上一次的基础上平移

_customLabel.transform =CGAffineTransformTranslate(_customLabel.transform,12,
30);

//提交动画

[UILabelcommitAnimations];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: