UI 动画之反射变换的平移

来源:互联网 发布:东京著衣淘宝上没有了 编辑:程序博客网 时间:2024/05/21 01:53

@interface ViewController ()


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

@property(nonatomic,strong)UILabel *customLabel;


//静止,用来对比

@property(nonatomic,strong)UIView *staticView;


@end



@implementation ViewController


- (void)viewDidLoad {

    [superviewDidLoad];

   

    

    //动画影响的属性:framecenterboundsbackgroundalphatransform

    

  

    //定义好自定义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];

}

0 0
原创粉丝点击