【问题标题】:Any difference between `self.backgroundcolor` and `self.layer.backgroundcolor`?`self.backgroundcolor` 和 `self.layer.backgroundcolor` 之间有什么区别吗?
【发布时间】:2017-04-05 04:17:25
【问题描述】:
@implementation AVSuperView

- (AVSuperView*)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
//        self.backgroundColor = [UIColor redColor];
        self.layer.backgroundColor = [[UIColor redColor] CGColor];
        AVLayout* avLayout = [[AVLayout alloc] init];

在自定义 UIView 中,例如上面,似乎self.backgroundColorself.layer.backgroundColor 是一样的。 self.backgroundColorself.layer.backgroundColor 的包装器吗?

【问题讨论】:

    标签: ios cocoa-touch core-animation


    【解决方案1】:

    self.backgroundColorself.layer.backgroundColor 的包装器吗?

    是的,就是这样。 framealphaopacity 以及其他各种属性也是如此(更不用说视图中的绘图实际上是图层中的绘图)。

    视图和它的底层是非常紧密地绑定在一起的。从某种意义上说,视图的存在只是为了赋予图层接收触摸的能力。

    【讨论】:

    猜你喜欢
    • 2013-09-13
    • 2014-09-18
    • 2015-06-14
    • 2011-05-23
    • 2011-02-15
    • 2011-11-27
    • 2022-01-18
    • 1970-01-01
    • 2015-03-30
    相关资源
    最近更新 更多