问题描述
谁能告诉我validateProperties()
和 invalidateProperties()
有什么区别?
Can any one tell me about what is the Difference between validateProperties()
and invalidateProperties()
?
推荐答案
标记一个组件,以便调用它的 commitProperties() 方法在稍后的屏幕更新期间.
失效是一种有用的机制,可以通过以下方式消除重复工作将组件更改的处理延迟到稍后的屏幕更新.例如,如果要更改文本颜色和大小,则更改颜色后立即更新颜色会很浪费然后在设置时更新大小.这样做更有效率更改这两个属性,然后以新的大小呈现文本,然后颜色一次.
Invalidation is a useful mechanism for eliminating duplicate work by delaying processing of changes to a component until a later screen update. For example, if you want to change the text color and size, it would be wasteful to update the color immediately after you change it and then update the size when it gets set. It is more efficient to change both properties and then render the text with its new size and color once.
无效方法很少被调用.一般来说,设置一个属性在组件上自动调用适当的失效方法.
Invalidation methods rarely get called. In general, setting a property on a component automatically calls the appropriate invalidation method.
被布局逻辑用来验证组件的属性调用 commitProperties() 方法.一般来说,子类应该覆盖 commitProperties() 方法而不是这个方法.
本质上,validate 直接调用 commitProperties,而 invalidate 等待下一帧来执行.始终使用无效.
Essentially, validate calls commitProperties directly while invalidate waits for the next frame to do it. Always use invalidate.
这篇关于validateProperties() 和 invalidateProperties() 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!