美文网首页
UIView 和 CALayer

UIView 和 CALayer

作者: 唱歌的鼻涕泡 | 来源:发表于2021-08-26 10:52 被阅读0次

从iOS的响应链开始说起

最近在看iOS 的响应链 看到了这样的关系


控件继承关系

因为UIView 继承自 UIResponder 所以其内部包括了 响应 点击等一些列手势的方法,

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
- (void)touchesEstimatedPropertiesUpdated:(NSSet<UITouch *> *)touches API_AVAILABLE(ios(9.1));

所以UIView 具有时间响应的能力。

@property(nonatomic,readonly,strong)                 CALayer  *layer;             
 // returns view's layer. Will always return a non-nil value. view is layer's delegate

直接去UIView 类中查看,发现了CALyer 是UIView的成员变量 ,所以UIView 属于是CALayer 的再次封装。所以真正的绘图部分还是交给了CALayer。

总结:所以UIView 是对CALAyer的调用封装,并继承UIResponder 具有相应事件

具体分析两者的方法可以查看UIView和Calayer的区别

相关文章

网友评论

      本文标题:UIView 和 CALayer

      本文链接:https://www.haomeiwen.com/subject/tkwyiltx.html