Layer的常见属性,隐式动画

     (1) layer:UIView之所以能显示到屏幕上,就是因为其内部有一个图层,在创建UIView对象时,UIView内部自动创建一个图层(CALayer对象),可以通过UIView的layer属性设置这个图层的相关东西。

     (2)UIView本身不能显示内容,当UIView需要显示到屏幕上时,会调用drawRect方法。然后把所绘内容放在自己的图层上。然后通过图层显示到屏幕上。

      (3)每个UIView内部都默认关联着一个CALaye对象(图层),称这个layer为Root Layer(根图层)。所有的非Root Layer都存在隐式动画,隐式动画时长为0.25秒。

      (4)隐式动画,在非Root Layer的部分属性发生改变时,产生的动画效果

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //创建图层
    CALayer *subLayer = [[CALayer alloc]init];
    //将图层添加view
    [self.view.layer addSublayer:subLayer];
    
    //- - - - - - 常用属性 - - - - - -//
    
    //设置图层的大小
    subLayer.bounds = CGRectMake(0, 0, 200, 200);
    
    //设置图层的显示位置
    subLayer.position = CGPointMake(100, 100);
    
    subLayer.backgroundColor = [UIColor redColor].CGColor;
    
    //设置锚点 
    subLayer.anchorPoint = CGPointMake(0.5, 0.5);
    
    //设置显示的内容
    UIImage *img = [UIImage imageNamed:@"1.jpg"];
    
    subLayer.contents = (id)img.CGImage;
    
}
/*隐式动画*/

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    
    CGPoint point = [touch locationInView:self.view];
    
    
    //关闭动画
    //    [CATransaction begin];
    //    [CATransaction setDisableActions:YES];

    
    
    //1修改位置
    _layer.position = point;
    
    //2.改变layer 的大小
    CGFloat num = arc4random_uniform(50)+30;
    
    _layer.bounds = CGRectMake(0, 0, num, num);
    
    //改变透明度
    _layer.opacity = arc4random_uniform(10)*0.1;
    
    //背景色
    _layer.backgroundColor = [UIColor colorWithRed:arc4random_uniform(10)*0.1 green:arc4random_uniform(10)*0.1 blue:arc4random_uniform(10)*0.1 alpha:1].CGColor;
    //设置边框的弧度
    
    _layer.cornerRadius = arc4random_uniform(30);
    
    //transform
    //_layer.transform =  CATransform3DMakeScale(2, 1, 1);

    //提交关闭动画
    //    [CATransaction commit];
    
}










  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值