图层是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. 在Eclipse中安装和使用TFS插件

    在Eclipse中安装插件的方法其实都一样,安装TFS的步骤如下: 下载TFS插件.你可以到微软的下载中心,下载TFS插件TFSEclipsePlugin-UpdateSiteArchive-10.0 ...

  2. 畅通工程2 HDOJ--1863

    畅通工程 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  3. Eclipse SVN插件安装与使用(2014.12.27——by小赞)

    安装参考:http://www.cnblogs.com/xdp-gacl/p/3497016.html 用法参考:http://blog.sina.com.cn/s/blog_8a3d83320100 ...

  4. python爬虫学习(2)__抓取糗百段子,与存入mysql数据库

    import pymysql import requests from bs4 import BeautifulSoup#pymysql链接数据库 conn=pymysql.connect(host= ...

  5. codeforces 358D

    题目链接:http://codeforces.com/contest/358/problem/D #include<cstdio> #include<iostream> #in ...

  6. 1115 HTML CSS

    1. HTML 全称HyperText Markup Language (超文本标记语言). 2. 网页=HTML文件 + Web服务器 + CSS文本. 3. Web服务器:处理浏览器请求,寻找资源 ...

  7. Jquery Mobile左右滑动效果

    首先在一个页面里面定义两个< div data-role="page">,这里为了突出重点,就没有写出footer和header.定义的页面如下: <body&g ...

  8. zookeeper与activemq最新存储replicatedLevelDB整合

    测试环境:三台VM虚拟机centos6.4 64位 mini版,IP分别为192.168.1.191/192/193. 测试目的:测试activemq的failover以及与zookeeper的整合 ...

  9. jqChart动态数据

    <link rel="stylesheet" type="text/css" href="../../css/jquery.jqChart.cs ...

  10. onInterceptTouchEvent和onTouchEvent调用时序

    onInterceptTouchEvent()是ViewGroup的一个方法,目的是在系统向该ViewGroup及其各个childView触发onTouchEvent()之前对相关事件进行一次拦截,A ...