ios UIView 的不透明度和 alpha 是一样的吗
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15381436/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is the opacity and alpha the same thing for UIView
提问by trillions
I want to use animation to change UIView's color to make it fade, however, somehow i can't access and set opacity, but i can set alpha. I wonder if alpha and opacity are the same? Search on the web and I didnt find a good answer. Thanks a lot for your help!
我想使用动画来更改 UIView 的颜色以使其褪色,但是,不知何故我无法访问和设置不透明度,但我可以设置 alpha。我想知道 alpha 和 opacity 是否相同?在网上搜索,我没有找到好的答案。非常感谢你的帮助!
回答by alex
Actually "opacity" means "value of alpha-channel" of your UIView
. When a view is fully opaque this means its alpha = 1
, when a view is fully transparent (non-opaque) its alpha = 0
.
实际上“不透明度”是指您的 .alpha 通道的“值” UIView
。当视图完全不透明时,这意味着它的alpha = 1
,当视图完全透明(非不透明)时,它的alpha = 0
.
As about properties of CALayer
and UIView
in Cocoa, yes, they provide the same functionality.
至于Cocoa的CALayer
和属性UIView
,是的,它们提供相同的功能。
回答by Cyrille
Just try by yourself!
自己试试吧!
CALayer
has opacity
from 0 to 1, while UIView
has alpha
from 0 to 1. They have the same visual effect.
CALayer
has opacity
from 0 to 1, while UIView
has alpha
from 0 to 1. 它们具有相同的视觉效果。
回答by Ravindhiran
Alpha affects everything drawn on the view.The background color's alpha affects the background color's transparency and anything else drawn on the view.i.e it brings about a frosty effect to whole view. Opacity means don't draw anything underneath, even if you are transparent, it just effects the current view.
Alpha 影响在视图上绘制的所有内容。背景颜色的 Alpha 影响背景颜色的透明度以及在视图上绘制的任何其他内容。即它会给整个视图带来冷淡的效果。不透明意味着不要在下面绘制任何东西,即使您是透明的,它也只会影响当前视图。