在iOS 中,UIButton、UIImage等UIView 之所以能够显示在屏幕上,是因为其内部有一个图层(CALayer)。通过UIView的layer 属性可以访问这个图层:

@property(nonatomic,readonly,retain) CALayer *layer; 

当UIView需要显示到屏幕上时,会调用 drawRect: 方法进行绘图,并且会将所有内容绘制在自己的图层上,绘图完毕后,系统会将图层拷贝的屏幕上,于是就完成了UIView的显示。

UIView中有两个容易混淆的属性, postion 和 anchorPoint(锚点)。postion用来设置CALayer 在父层中的位置,anchorPoint决定着CALayer上的哪个点会在postion点上。举个例子来说,红色图层要加在绿色图层上。

(1)positon为(100,100),anchorPoint为(0,0),效果图如下

(2)positon为(100,100),anchorPoint为(0.5,0.5),效果图如下

(3)positon为(100,100),anchorPoint为(1,1),效果图如下

(4)positon为(100,100),anchorPoint为(1,0.5),效果图如下

即:anchorPoint决定着CALayer上的哪个点会在postion点上。

CALayer 的 position和anchorPoint属性的更多相关文章

  1. ios开发图层layer与核心动画二:CATransform3D,CAlayear和UIView区别,layer的position和anchorpoint

    一:CATransform3D #import "ViewController.h" @interface ViewController () @property (weak, n ...

  2. position和anchorPoint笔记

    position和anchorPoint是CAlayer的两个属性.     我们以前修改一个控件的位置都是能过Frame的方式进行修改.     现在利用CALayer的position和ancho ...

  3. CALayer 易混淆的两个属性 - position和anchorPoint

    1.简单介绍 CALayer有2个非常重要的属性:position和anchorPoint @property CGPoint position;                           ...

  4. CALayer属性:position和anchorPoint

    一.position和anchorPoint 1.简单介绍 CALayer有2个非常重要的属性:position和anchorPoint @property CGPoint position; 用来设 ...

  5. CALayer的position,anchorPoint属性 与UIView的frame 属性

    彻底理解CALayer的position,anchorPoint属性 与UIView的frame 属性 一.position,anchorPoint两者都是CALayer的属性,都是CGPoint点 ...

  6. 彻底理解position与anchorPoint

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

  7. position与anchorPoint

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

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

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

  9. iOS-CALayer中position与anchorPoint详解

    iOS-CALayer中position与anchorPoint详解 属性介绍 CALayer通过四个属性来确定大小和位置, 分别为:frame.bounds.position.anchorPoint ...

随机推荐

  1. Java注释模板

    /**   *    * 项目名称:${project_name}   * 类名称:${type_name}   * 类描述:   * 创建人:${user}   * 创建时间:${date} ${t ...

  2. CSS水平、垂直居中小结

    我们在实际工作中经常会遇到需要水平居中或者垂直居中的场景,今天我们就来看一下如何设置水平居中和垂直居中. 首先来看水平居中. 一.水平居中设置-行内元素. 如果被设置元素为文本.图片等行内元素时,水平 ...

  3. Tesseract——OCR图像识别 入门篇

    Tesseract——OCR图像识别 入门篇 最近给了我一个任务,让我研究图像识别,从我们项目的screenshot中识别文字信息,so我开始了学习,与大家分享下. 我看到目前OCR技术有很多,最主要 ...

  4. java Date和String转换总结

    java.util.Date和String类型的转换是非常常用的,现在总结一下: 1. Date转换为String //Date --->String DateFormat dft = new ...

  5. easyui源码翻译1.32--Messager(消息窗口)

    前言 使用$.messager.defaults重写默认值对象.下载该插件翻译源码 消息窗口提供了不同的消息框风格,包含alert(警告框), confirm(确认框), prompt(提示框), p ...

  6. Android HttpClient get传递数组

    url请求格式: String url = "http://10.80.7.26:" + +;

  7. Android-UGallery

    public class UGallery extends Gallery { public UGallery(Context context, AttributeSet attrs) { super ...

  8. WCF - Overview

    WCF stands for Windows Communication Foundation. The elementary feature of WCF is interoperability. ...

  9. WCF - Self Hosting

    WCF - Self Hosting Here, the WCF service is hosted in a console application. Given below is the proc ...

  10. MySQL information_schema表查询导致内存暴涨

    case:下面的一条sql语句,导致mysql实例内存暴涨: select * from tables where table_name not in(select table_name from p ...