单视图heirachy中的UIView组不透明度 [英] UIView group opacity in single view heirachy
问题描述
我正在编写一个UI库,我希望能够拥有UIViews的alpha,就像设置了UIViewGroupOpacity info.plist一样。请参阅以下链接:
I am writing a UI library in which i would like to be able to have the alpha of the UIViews as if the UIViewGroupOpacity info.plist ket was set. See following links:
但是,就像我一样写一个lib,我不希望项目必须设置这个全局密钥,并影响主项目的行为。
But, as I am writing a lib, I dont want the projects to have to set this global key, and effect the behaviour of the main project.
还有其他方法可以实现吗?我不想遍历所有子视图并设置每个子视图的alpha,因为包含我的lib的项目可能启用了此键...
Is there any other way of achieving this? I dont want to cycle through all the subviews and set alpha of each subview, as the project that includes my lib might have this key enabled...
推荐答案
是的,您可以设置 shouldRasterize
。
Yes there is, you can set shouldRasterize
of the view's layer.
containerView.layer.shouldRasterize = YES;
// Not setting rasterizationScale, will cause blurry images on retina displays:
containerView.layer.rasterizationScale = [[UIScreen mainScreen] scale];
这与 UIViewGroupOpacity
具有相同的效果但仅适用于 containerView
及其子视图。
This will have the same effect as UIViewGroupOpacity
but only for containerView
and it's subviews.
这篇关于单视图heirachy中的UIView组不透明度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!