先来看一下UIView和CALayer之间的关系:
CAlayer继承了NSObject,负责显示内容,不能响应事件,仅能判断某点是否在该视图内。- (BOOL)containsPoint:(CGPoint)p;
UIView继承了UIResponder,负责处理触摸事件,参与响应者链。每一个view都有关联了一个默认的CALayer对象,我们可以通过重写view的+(Class)layerClass方法来自定义关联到view上的layer。而且UIView还遵守了CALayerDelegate协议,并且将关联的layer的代理人设置为自己。
接着来看一下UIView的一些表示位置信息的属性:
@property(nonatomic) CGRect frame;
// use bounds/center and not frame if non-identity transform.
//if bounds dimension is odd, center may be have fractional part
@property(nonatomic) CGRect bounds;
// default bounds is zero origin, frame size. animatable
@property(nonatomic) CGPoint center;
// center is center of frame. animatable
然后来看一下CALayer的一些表示位置信息的属性:
@property CGRect frame;
/* Unlike NSView, each Layer in the hierarchy has an implicit frame
* rectangle, a function of the `position', `bounds', `anchorPoint',
* and `transform' properties. When setting the frame the `position'
* and `bounds.size' are changed to match the given frame. */
@property CGRect bounds;
/* The bounds of the layer. Defaults to CGRectZero. Animatable. */
@property CGPoint position;
/* The position in the superlayer that the anchor point o