图层是core animation的基础, UIView之所以能显示在屏幕上,靠的是其内部的这个图层,即每个UIView 都有 CALayer,可通过UIView.layer或者[UIView layer]访问到这个图层。UIView可以响应事件,而CALayer只负责显示。
 
一. 基本属性设置
    
1. 设置阴影和透明度
    //创建image view
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"curry.jpg"]];
imgView.frame = CGRectMake(, , , );
[self.view addSubview:imgView]; //设置阴影的颜色为灰色
imgView.layer.shadowColor = [UIColor grayColor].CGColor;
//阴影的偏移大小,右下角偏移
imgView.layer.shadowOffset = CGSizeMake(, );
//0.5表示半透明
imgView.layer.shadowOpacity = 0.5;
效果:
2.设置圆角效果
    //设置圆角半径为10
imgView.layer.cornerRadius = 10;
imgView.layer.masksToBounds = YES;
效果:

3.设置边框

    //设置黄色边框大小为5像素
imgView.layer.borderWidth = 5;
imgView.layer.borderColor = [UIColor yellowColor].CGColor;

效果:

4.旋转

    //设置旋转效果
imgView.layer.transform = CATransform3DMakeRotation(M_PI_4, 1, 1, 1);//顺时针旋转45°

效果:

5. 缩放
    //设置缩放效果
imgView.layer.transform = CATransform3DMakeScale(0.5, 1, 0);//x轴缩小0.5倍

  

效果:

 
 二.新建图层
 
引用QuartzCore.framework
    CALayer *layer = [CALayer layer];
layer.backgroundColor = [UIColor blackColor].CGColor;
layer.bounds = CGRectMake(0, 0, 100, 100); layer.position = CGPointMake(200, 200);
layer.anchorPoint = CGPointMake(0.5, 0.5);
layer.cornerRadius = 10;
layer.masksToBounds = YES;
layer.contents = CFBridgingRelease([UIImage imageNamed:@"curry.jpg"].CGImage); [self.view.layer addSublayer:layer];

  

 
 

iOS Core Animation学习总结(1)--CALayer常用属性的更多相关文章

  1. iOS Core Animation学习总结(3)--动画的基本类型

    一. CABasicAnimation (基础动画) 移位: CABasicAnimation *animation = [CABasicAnimation animation]; //keyPath ...

  2. iOS Core Animation学习总结(2)--实现自定义图层

    一. 创建图层继承于CALayer,并在子类实现drawInContext方法 @interface CTLayer : CALayer @end @implementation CTLayer -( ...

  3. 转 iOS Core Animation 动画 入门学习(一)基础

    iOS Core Animation 动画 入门学习(一)基础 reference:https://developer.apple.com/library/ios/documentation/Coco ...

  4. iOS——Core Animation 知识摘抄(三)

    原文地址:http://www.cocoachina.com/ios/20150105/10827.html CAShapeLayer CAShapeLayer是一个通过矢量图形而不是bitmap来绘 ...

  5. iOS Core Animation 简明系列教程

    iOS Core Animation 简明系列教程  看到无数的CA教程,都非常的难懂,各种事务各种图层关系看的人头大.自己就想用通俗的语言翻译给大家听,尽可能准确表达,如果哪里有问题,请您指出我会尽 ...

  6. Core Animation学习总结

    文件夹: The Layer Beneath The Layer Tree(图层树) The Backing Image(寄宿层) Layer Geometry(图层几何学) Visual Effec ...

  7. iOS - Core Animation 核心动画

    1.UIView 动画 具体讲解见 iOS - UIView 动画 2.UIImageView 动画 具体讲解见 iOS - UIImageView 动画 3.CADisplayLink 定时器 具体 ...

  8. iOS——Core Animation 知识摘抄(四)

    原文地址http://www.cocoachina.com/ios/20150106/10840.html 延迟解压 一旦图片文件被加载就必须要进行解码,解码过程是一个相当复杂的任务,需要消耗非常长的 ...

  9. IOS Core Animation Advanced Techniques的学习笔记(五)

    第六章:Specialized Layers   类别 用途 CAEmitterLayer 用于实现基于Core Animation粒子发射系统.发射器层对象控制粒子的生成和起源 CAGradient ...

随机推荐

  1. 单实例 winform zz

    (引用了 Microsoft.VisualBasic.ApplicationServices)SingleInstanceApplicationWrapper.cs using System.Wind ...

  2. Wildfly 中支持jersey,并websocket的默认配置修改。

    以下为在jboss安装相对路径来写的.1.\domain\configuration\domain.xml修改内容: 注释关键字jaxrs存在的四行.修改后如下: <!--<extensi ...

  3. Bzoj 1975: [Sdoi2010]魔法猪学院 dijkstra,堆,A*,K短路

    1975: [Sdoi2010]魔法猪学院 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 1357  Solved: 446[Submit][Statu ...

  4. Kruskal算法构造最小生成树

    Kruskal算法来构造最小生成树,我总结了分为以下步骤: (1)建图,构造Kruskal边集,边集元素应该包括该边的起始顶点.终止顶点.权值: (2)将边集按权值从小到大的顺序进行排序: (3)从小 ...

  5. 彻底理解position与anchorPoint - Wonderffee's Blog(转)

    引言 相信初接触到CALayer的人都会遇到以下几个问题: 为什么修改anchorPoint会移动layer的位置?CALayer的position点是哪一点呢?anchorPoint与positio ...

  6. 问题-[WIN764位系统]操作UDL驱动不全处理

    http://www-01.ibm.com/support/docview.wss?uid=swg21503768 方法# 1 单击“开始——运行” 输入一个命令类似如下:        C:\Win ...

  7. hdoj 2036 改革春风吹满地

    改革春风吹满地 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  8. cocos 事件转发

    CCDirector在函数setOpenGLView中设置pobOpenGLView,同时会掉用 m_pobOpenGLView->setTouchDelegate(m_pTouchDispat ...

  9. ASP.NET MVC- VIEW Overview Part 1

    The purpose of this tutorial is to  provide you with a brief introduction to ASP.NET MVC views, view ...

  10. 使用CLRMD编写一个自己的C#调试器

    博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:使用CLRMD编写一个自己的C#调试器.