when my app comes out of the background the animation has stopped. which is normal. but i want to restart my animation from the current state. how do i do that without my snapping all over the place.
[UIView animateWithDuration:60 delay:0 options:(UIViewAnimationOptionCurveLinear |UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat | UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionBeginFromCurrentState) animations:^{
[bg setFrame:CGRectMake(0, 0, 1378, 1005)];
} completion:nil];
i tried putting a set frame in front of the animation but that just makes it snap.
[bg setFrame:CGRectMake(0, 0, 1378, 1005)];
any ideas?
Well if I understand the question right way, you're trying to create an animation and stop it in the middle.
In this case i would suggest you to use some kind of "state" variable to store the state of animation (the frame property for example). This variable you can use in further code to put the object that is being animated in correct position. This can be done in animationDidStop function (animationDidStop:finished:). In order to implement this function you will have to use the delegation. It means to set AppNameViewController (or some other unique object for entire application) as a delegate for an animation and write the implementation in its m-file. This will allow you to run "position setup" code at the end of the animation.
Next task is to store the animation state. While running animation, Core Animation framework creates a bunch of intermediate layers (presentation layers). And these layers are displayed during the animation and then they're deleted. And when animation finishes execution the object is just gets placed into it's final state. Actually you have to set this when you create so called "explicit animation" (and if you don't, animation will play but the object will jump back in the end). Each of these presentation layers has a set or it's own copy of all the properties that are called "animatable properties". When one of the animatable properties is set as a key for the animation, Core Animation calls (BOOL)needsDisplayForKey that returns YES/NO. It tells the Core Animation whether changes to the specified key required the layer to be redisplayed. To "redisplay" means to call drawInContext method for the presentation layer. Here you can grab the properties of the presentation layer that is currently displayed and put them into "state" variable.
The animation is played in thread and in order to set the "state" variable I used delegation. It required to subclass CALayer (lets' say AnimLayer) and define a protocol in it with just one method that stores the "state". This method has one parameter which is the state. Then I implemented the protocol method that stores the state in AnimLayer class and set the unique object as a delegate. So those presentation layers (AnimLayer copies) do not store the state themselves. Instead the "state" value passed as a parameter to the delegate function is stored by unique object in main thread.
I did something like that but my task was a bit different. I don't know the easier way, sorry. Hope this helps.