Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explicitly disabling UIView animation in iOS4+

I have been reading that Apple recommends to use block-based animations instead of CATransaction

Before, I was using this code to disable animations:

[CATransaction begin];
[CATransaction setDisableActions: YES];
// !!! resize
[CATransaction commit];

Is there a new recommended method to do this, or is this still okay?

like image 464
P i Avatar asked Mar 26 '11 16:03

P i


People also ask

How do you stop all animations in Swift?

I want to stop animation and remove hint label once user presses the text field to enter data. func removeAnimation(textField: UITextField) { view. layer. removeAllAnimations() self.

Does UIView animate need weak self?

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.

Does UIView animate run on the main thread?

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.

How does UIView animate work?

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.


2 Answers

[UIView setAnimationsEnabled:NO];
//animate here
[UIView setAnimationsEnabled:YES];
like image 113
Joshua Weinberg Avatar answered Sep 21 '22 03:09

Joshua Weinberg


For iOS 7 and above this can now be accomplished with:

[UIView performWithoutAnimation:^{
    // Changes we don't want animated here
    view.alpha = 0.0;
}];
like image 23
Brentley Jones Avatar answered Sep 21 '22 03:09

Brentley Jones