In iOS, a common pattern for ensuring UI updates execute only once in a predictable manner is to queue up a method that will be run on the next iteration of the run loop and ensure only one is queued up.
For example, multiple properties of UIView
will call setNeedsLayout
in one iteration of the run loop, then a subsequent iteration will call layoutIfNeeded
(which in turn calls layoutSubviews
. This ensures that the more intensive operation that can cause additional side-effects only happens once in a predictable manner.
This pattern is implemented when running inside of a callback (ex: event iteration off of the main loop) and requires a single method, a boolean, and a means of requesting execution.
Is there a name for this type of design pattern?
Aucun commentaire:
Enregistrer un commentaire