ryleigh
ryleigh

Reputation: 218

Why are iOS animations slow the first time they are run?

It seems to me that the first time I run an animation (animating the frame of a UIView, or the position of a CALayer, etc) it is quite choppy, and subsequent animations are smooth.

What would be causing this, and is there any way to pre-cache the animation?

Note: this question is quite similar to this one: UIImageView animations lag at first run, but UIImages are not being used in my animations.

Upvotes: 13

Views: 2016

Answers (3)

Nico
Nico

Reputation: 3826

Assuming you are using [UIImage imageNamed: @"herp.png"] the image will be cached. If the image is drawn a lot it will be unpacked into memory, else it will do a lazy load of the image and cause a stutter.

Upvotes: 0

Majid
Majid

Reputation: 383

If you have a TextField, which I assume is what receives your user input. Use the UITextFieldDelegate methods Did and not Should

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
//Do textfield animations and other view animations here

}

Don't do your animations in;

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
//Don't do textfield animations and other view animations here
//This is where the system does its own animations; raising the keyboard, etc
}

Upvotes: 2

Tim
Tim

Reputation: 14446

Run it in viewDidAppear, instead of viewWillAppear. Caching should occur after the image did appear, and it should look the same to the user.

Upvotes: 0

Related Questions