Search code examples
uiviewanimationuiviewanimation-curve

ios UIView animation curves


Is there any way to do things the "short and easy" way like below? The curve appears to still use EaseOut.

[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView animateWithDuration:0.5 animations:^{
    // ... do stuff here
}];

Solution

  • You are mixing two different kinds of UIView-animations. You should be using something like this either of these:

    [UIView animateWithDuration:0.5
                          delay:0.0
                        options:UIViewAnimationOptionCurveEaseIn
                     animations:^{
                        // ... do stuff here
                   } completion:NULL];
    

    This came from the newer block-based UIView-animation API. The first line, on the other hand, is part of the older UIView animation API that looks like this:

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
    // ... do stuff here
    [UIView commitAnimations];
    

    They do the same thing and you can use either (though Apple recommends the block-based API since it is easier/cleaner to do callbacks after the animation finishes).