简体   繁体   English

UIView反映CALayer属性

[英]UIView reflect CALayer properties

When changing a UIView's basic view properties (eg backgroundColor, alpha/opacity, frame) is it actually the layer that get's those changes under the hood? 当更改UIView的基本视图属性(例如backgroundColor,alpha / opacity,frame)时,实际上是在底层进行这些更改的图层吗? To put it simple, when I change the UIViews alpha for example is it actually the CALayers opacity property that changes? 简单来说,例如,当我更改UIViews alpha时,实际上是CALayers opacity属性发生了变化吗?

On iOS, views are fairly thin wrappers around layers, and most view properties like the frame/bounds, alpha, etc. are indeed just manipulating the underlying layer. 在iOS上,视图是围绕层的相当薄的包装器,并且大多数视图属性(例如帧/边界,alpha等)实际上只是在操纵底层。 You can verify your alpha example with a little snippet of code in a view controller: 您可以在视图控制器中用一小段代码来验证您的alpha示例:

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    self.view.alpha = 0.5f;
    NSLog(@"Layer alpha: %f", self.view.layer.opacity);

    self.view.layer.opacity = 1.0f;
    NSLog(@"View alpha: %f", self.view.alpha);
}

This prints out: 打印输出:

Layer alpha: 0.500000
View alpha: 1.000000

So we can see that the view alpha and layer opacity are the same thing. 因此,我们可以看到视图alpha和图层不透明度是同一件事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM