码迷,mamicode.com
首页 > 其他好文 > 详细

CALayer 与 UIView

时间:2016-03-14 23:06:17      阅读:406      评论:0      收藏:0      [点我收藏+]

标签:

1、关系
On iOS, every UIView is backed by a Core Animation CALayer. Simply speaking,UIView inherit from NSResponder,handle events from users, contains CALayer,which inherit from NSObject,mainly focus on rendering,animation etc.
 
One thing UIViews provide over CALayers is built-in support for user interaction. They handle hit-testing on touches and other related actions that you would need to build yourself if managing a hierarchy of CALayers. It‘s not that hard to implement this yourself, but it is extra code you‘d need to write when building a CALayer-only interface.
 
You will often need to access the underlying layers for a UIView when performing more complex animations than the base UIView class allows. UIView‘s animation capabilities have grown as the iOS SDK has matured, but there are still a few things that are best done by interacting with the underlying CALayer.
 
2、功能
UIView 主要是对显示内容的管理,CALayer 主要侧重显示内容的绘制。
 
3、动画 (可参考 objc.io - 动画 部分)
在对UIView 的属性修改时不会产生默认动画,而对单个 layer 属性直接修改会产生默认动画。因为UIView 默认情况下禁止了 layer 动画,但是在 animation block 中又重新启用了它们。
 
4、CALayer
 
The neat thing about the CALayer class is that it contains a lot of properties that you can set on it to affect the visual appearance, such as:
  • The size and position of the layer
  • The layer’s background color
  • The contents of the layer (an image, or something drawn with Core Graphics)
  • Whether the corners of the layers should be rounded
  • Settings for applying a drop shadow to the layer
  • Applying a stroke around the edges of the layer
  • And much more!
 
The other neat thing about the properties on CALayer is that most of them are animatable. 
 
 
参考资料:
 
 
 

CALayer 与 UIView

标签:

原文地址:http://www.cnblogs.com/stonewong/p/5277571.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!