如果你有不透明视图(opaque views)没有透明度定义的视图设置他们的opaque属性为YES。
苹果的文档 Apple documentation中有对这个属性的描述:
This property provides a hint to the drawing system as to how it should treat the view. If set to YES
, the drawing system treats the view as fully opaque, which allows the drawing system to optimize some drawing operations and improve performance. If set to NO
, the drawing system composites the view normally with other content. The default value of this property is YES
.
这个属性提供了一个提示给图系统如何对待这个视图。如果设置为YES,绘制系统将会把这个视图视为完全不透明。这样允许系统优化一些绘制操作和提高性能。如果设置为NO,绘图系统会复合这个视图和其他的内容,这个属性的默认值是YES
在相对静态的屏幕上,设置opaque属性不会有什么大问题。尽管如此,如果你的视图是嵌入在一个scrollView,或者是一个复杂的动画的一部分,不设置这个属性绝对会影响你的程序的性能
你也可以使用虚拟机中Debug ------> Color Blended Layers选项 在你的模拟器中形象化的看见没有设置为不透明(opaque)的视图.你的目标应该是尽可能多的设置视图为透明。红色的为在绘图中为透明的绿色为不透明
优化后如下图