ios - 如果我使用 clearColor 作为 backgroundColor,我需要将 UIVIew.opaque 显式设置为 NO 吗?

标签 ios uiview

需要我写:

view.opaque = NO;

对于每个具有透明 backgroundColor 或小于 1 alpha 的 View ?

从文档看来是这样:

An opaque view is expected to fill its bounds with entirely opaque content—that is, the content should have an alpha value of 1.0. If the view is opaque and either does not fill its bounds or contains wholly or partially transparent content, the results are unpredictable. You should always set the value of this property to NO if the view is fully or partially transparent.

但事实上,我从来没有那样做,也很少看到其他人那样做,而且代码工作得很好。

如果事实证明我确实需要将 opaque 设置为 NO,那么我是时候找出所有错误的代码并纠正它们了。

最佳答案

你应该明确地设置这个,尽管如果你是从 Nib 充气,你可以只在 InterfaceBuilder/Xcode 中设置这个属性。此属性用作图形上下文的快捷方式标志,因此它不必尝试推断您的 View 是否透明。

代码仍然有效,但运行时必须进行推断。此外,由于 iOS 使窗口的某些区域无效而不使其他区域无效的方式,如果您的 View 被标记为不透明但实际上并非如此,您可能会不时遇到一些奇怪的行为。

关于ios - 如果我使用 clearColor 作为 backgroundColor,我需要将 UIVIew.opaque 显式设置为 NO 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7730663/

相关文章:

ios - 自定义 UIview 与 UIBezierPath 就像冰淇淋甜筒

ios - 从 UIView 执行 segue

从 App Store 重新安装的 iPhone/IOS 应用程序具有旧角标(Badge)和值(value)

iOS 11 错误,didselectrowatindexpath 调用同时用两根手指点击单元格

ios - 未生成适用于 iOS 的 Xcode 6.1 静态库 .a

iphone - 如何在 Xcode for iOS 中调试涉及 CALayer 的无限循环 "crash"并在搜索期间查看布局?

ios - swift : Clear UIView

ios - 如何使用 calabash iOS 从源代码中获取值(value)

ios - 使用 View iOS 滚动 uilabel 时保持标签文本与屏幕居中对齐?

ios - TableView 之上的 UiView