iOS: Windows, Views

官方文档
基本概念:
Windows本身没有可见的内容,但是为应用的view提供一个基本的容器
Views定义了用户可以对window填充内容的一部分,比如可以在view内显示image, text ,shape 
可以在view内组织、管理其他views
每一view都有一个layer对象支持,比如 CALayer 类。这些layer对象管理backing store并处理view相关的动画;多数的操作都可以通过UIView执行,但是在需要更多rendering和animation相关的操作时,用户可以通过这个对象来实现。每个view都有一个 layer  属性
UIView使用 on-demand drawing model模式来绘制内容。当view第一次出现在屏幕上时,系统要求view绘制内容,随后系统会捕捉这个内容的一个snapshot,如果view的内容没有发生改变,view的绘制代码一直不会被调用,而是使用snapshot展示;如果内容发送了改变,系统会收到一个通知然后view会重新绘制这部分内容并获取一个新的snapshot
当view的内容发生改变的时候不需要直接重绘这部分内容,而是调用方法the  setNeedsDisplay  或 setNeedsDisplayInRect: 让view无效,这些方法会告诉系统view的内容已经发生改变并需要在下一个机会点重绘。这段时间内可以有机会来批量处理view。
绘制的view内容以bitmap的形式保存,view的几何属性并不会总是引起bitmap的重新创建,而是通过   contentMode 来决定,这个属性会在改变view的 frame  or  bounds  的高、宽属性;变换一个view的 transform  属性。这里有些情况下的变换可能会使图片变形。如果想尽可能少的重新绘制内容,就将contentMode设置为  UIViewContentModeScaleToFill , 如果想每次重绘就将其设置为  UIViewContentModeRedraw 。 这样每次的内容几何上的变化都会导致系统调用drawRect:方法。
实际的绘制过程依赖于view和其配置,系统的view通过调用私有方法显示这些内容。这些系统的view会暴露接口来配置view的实际外观,对于定制的UIView类,通常通过重载 drawRect:  来绘制view的内容。
Stretchable Views: 使指定的view为可拉伸  contentStretch 属性指定view的可拉伸区域,可以保证view的部分区域可拉伸,保证总体不会变形;这个参数会接受一个矩形框,其值为0到1,这个属性只支持如下几个content mode:   UIViewContentModeScaleToFill UIViewContentModeScaleAspectFit , and UIViewContentModeScaleAspectFill
内建的Animation支持:
frame —Use this to animate position and size changes for the view.
bounds —Use this to animate changes to the size of the view.
center —Use this to animate the position of the view.
transform —Use this to rotate or scale the view.
alpha —Use this to change the transparency of the view.
backgroundColor —Use this to change the background color of the view.
contentStretch —Use this to change how the view’s contents stretch.   
UIKit默认的坐标系统是以左上角为坐标原点向下、右边延伸;一些iOS库比如Core Graphics和OpenGL ES使用的是以左下角为坐标原点的坐标系,在使用这些的时候需要注意坐标转换
Frame, Bounds, Center
Frame指的是view相对其父view的位置和大小
bounds属性值得是相对view自身的位置和大小
center指的是相对于父view的view中心位置坐标
frame,bounds,center:其中frame,center可以用来变换view大小、移动view等操作;bounds主要是绘制view内容的时候用到。这几个属性值是可以相互影响的,改变某一个值,另外两个可能会跟着改变。默认的一个view的frame是不会截断来保持跟super view保持一致的。但是可以通过设置 clipsToBounds  属性来设置这个。
Coordinate System Transform:affine transform 可以实现不同坐标系统之间的转换;
To modify your entire view, modify the affine transform in the  transform   property  of your view.
To modify specific pieces of content in your view’s  drawRect:  method, modify the affine transform associated with the active graphics context. 
Points versus Pixels:一个point并不等价于一个pixel;point隔绝了硬件层的区别,保证代码有统一的空间值和坐标;代码在执行时系统会自动将point映射到指定硬件的pixel值
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值