需要我写:
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/