iOS animation experts! What are the pros and cons of each method? I know Apple recommends blocks instead of the old UIView
animation methods (UIView
beginAnimations
, etc), but what about CAAnimation
? When would you use one method vs the other? Is there a tradeoff in terms of performance?
UIView: Views have more complex hierarchy layouts. They can receive user interactions like taps, pinches, cliks and more. Working with UIViews happens on the main thread, it means it is using CPU power. CALayer: Layers on other hand have simpler hierarchy.
No, it is not needed in this case. animations and completion are not retained by self so there is no risk of strong retain cycle.
The contents of your block are performed on the main thread regardless of where you call [UIView animateWithDuration:animations:] .
CATransaction is the Core Animation mechanism for batching multiple layer-tree operations into atomic updates to the render tree. Every modification to a layer tree must be part of a transaction. Nested transactions are supported.
1) There is not much difference in terms of memory expenses between UIView's animation blocks and CALayers's
CAAnimation
nor in terms of the objects themselves.
2) There are limitations to the type of animations you can achieve with UIView's
animation, so you might be forced to use CAAnimation
anyway.
3) For those types of simpler animations that UIView can handle, it is usually a simpler API to use than that of CAAnimation
.
As miamk said, there are limitations to the types of animations you can achieve using the [UIView animateWith] method series. Personally I use CAAnimation, but that is because I am accustom to setting up animations that way. I feel you have more control. I tend to spend a day making a CAAnimation really really fine-tuned and then add it to my UIView extensions class so any view can use it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With