I need to handle a case where you can do something with or without animation, instead of:
if (animation)
{
[UIView animateWithBlock:^(){...}];
}
else
{
...
}
I want to do:
[UIView animateWithBlock:^(){...} duration:(animation ? duration : 0)]
but not sure if it works, even if it does, is there any overhead for using this instead of directly change the view?
Thanks
it queries the views objects for changed state and gets back the initial and target values and hence knows what properties to change and in what range to perform the changes. it calculates the intermediate frames, based on the duration and initial/target values, and fires the animation.
You don't need to use [weak self] in static function UIView. animate() You need to use weak when retain cycle is possible and animations block is not retained by self.
The contents of your block are performed on the main thread regardless of where you call [UIView animateWithDuration:animations:] . It's best to let the OS run your animations; the animation thread does not block the main thread -- only the animation block itself.
Animations can add visual cues that notify users about what's going on in the app. In iOS, animations are used extensively to reposition views, change their size, remove them from view hierarchies, and hide them.
What I do in this cases, is to create a block that contains all the animations I want to make. Then execute an UIView animation passing the animation block as a parameter, or directly calling that block, whether I want it to be animated or not. Something like this :
void (^animationBlock)();
animationBlock=^{
// Your animation code goes here
};
if (animated) {
[UIView animateWithDuration:0.3 animations:animationBlock completion:^(BOOL finished) {
}];
}else{
animationBlock();
}
That would avoid the overhead
According to the Apple docs:
If the duration of the animation is 0, this block is performed at the beginning of the next run loop cycle.
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