CALayer的基本使用

//1.圆角

//只给父层倒圆角无效

imgView.layer.cornerRadius= 100;

//此属性可以让UIImageView的所有子图层父图层一起变化

//imgView.layer.masksToBounds = YES;

//2.阴影

imgView.layer.shadowColor= [UIColor blueColor].CGColor;

imgView.layer.shadowOffset= CGSizeMake(10, 10);

imgView.layer.shadowOpacity = 0.8;

//3.设置transform,形变

//(1)平移

imgView.layer.transform= CATransform3DMakeTranslation(0, -100, 0);

//(2)旋转

//沿哪个轴旋转值就为1

imgView.layer.transform= CATransform3DMakeRotation(M_PI, 0, 0, 1);

//(3)缩放

imgView.layer.transform= CATransform3DMakeScale(0.5, 1, 1);

//Documents中搜索transform3D来获取keyPath

//向上移动100

[imgView.layersetValue:@-100 forKeyPath:@"transform.translation.y"];

沿z轴逆时针旋转45度

[imgView.layersetValue:@-M_PI_4 forKeyPath:@"transform.rotation.z"];

//自定义CALayer

//1.必须把自定义的层添加到父图层上去显示。

[self.view.layeraddSublayer:myLayer];

//2.设置图层的显示属性

//尺寸和颜色

myLayer.bounds =CGRectMake(0, 0, 200, 200);

myLayer.backgroundColor =[UIColor redColor].CGColor;

//显示位置,默认为中心点,具体位置由锚点决定。

myLayer.position =CGPointMake(100, 100);

//锚点,默认值为0.5,0.5

myLayer.anchorPoint =CGPointMake(0.5, 0.5);

//position和anchorPoint的值决定了层的显示位置。

//Layer在放大缩小时是以锚点为中心点进行放大缩小的。

UIImage *image = [UIImage imageNamed:@"2012100413195471481.jpg"];

myLayer.contents = (id)image.CGImage;

//淡入淡出动画,改变layer的透明度,范围是0到1。myLayer.opacity

//self.view.layer是rootLayer,无隐式动画效果。//所有的非rootLayer存在隐式动画效果。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值