Reputation: 1931
I need to implement very custom animation on iOS 3.2 So, neither I can't use block animations nor UIKit animations before 4.0. I try to use Core Animation.
Here's my code:
[CATransaction begin];
[CATransaction setAnimationDuration: 3.0];
[CATransaction setDisableActions: YES];
someView.frame = CGRectMake(endX, 0, endWidth, height);
// a lot of another property changes
[CATransaction commit];
Unfortunately, it doesn't work: views change size/opacity immediately, without any animation.
Here's my attempts:
Solution requirements:
Upvotes: 0
Views: 960
Reputation: 131398
The code you posted explicitly disables animations. This line is the culprit:
[CATransaction setDisableActions: YES];
By making that call, all the changes made in your transaction will be committed immediately, without animating. Get rid of that line and the changes should animate.
If you need a custom curve you might want to use a CABasicAnimation, as someone else suggested. Indeed, CAAnimation objects only apply to a single layer, so you'd have to create multiple CAAnimation objects.
Alternately, you should be able to use the CATransaction method setAnimationTimingFunction, and pass it a custom timing function that you create. See the CAMediaTimingFunction class reference. Specifically take a look at the method functionWithControlPoints::::, which lets you create a timing function by specifying the control points for a bezier curve that describes your timing function. You are limited to a single cubic bezier that starts at 0,0 and ends at 1,1. There is no direct support for more complex timing functions, although I have seen hacks that achieve more complex effects.
Upvotes: 1
Reputation: 56625
If you only want to have a custom timing function then you can do it with a CABasicAnimation. You can create a custom timing function (which is a bezier curve from (0,0) to (1,1) with two control points that you can specify.
If that is not enough for you (if you need more than 2 control points for your timing function) then you would have to use a CAKeyframeAnumation. Then you can specify as many values as you want (using the values
property (an array).
In both cases you would create a animation object for the keypath "frame" and add the animation to the views layer. Note that animating a property explicitly doesn't change the value so after the animation te frame will go back to its original value unless you both animate and change the value
Upvotes: 0
Reputation: 21221
Am not sure about if this is what you want or not, but you could use UIView animations
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:3.0];
someView.frame = CGRectMake(endX, 0, endWidth, height);
// a lot of another property changes
[UIView commitAnimations];
Upvotes: 0