I’m trying to animate two images moving across the screen using Monotouch. I’ve been looking into CATransaction and Animation group, but MonoTouch examples are few and fair between, and both these objects seem to apply to only one layer.
Would someone be able to point in the right direction on what sort of object to use to animate both images at the same time?
Thanks
MovePos(img);
MovePos(img2);
public void MovePos (UIView view)
{
var theAnimation = CABasicAnimation.FromKeyPath ("position");
theAnimation.Duration = 2;
theAnimation.From = NSValue.FromPointF (new PointF (74, 74));
theAnimation.To = NSValue.FromPointF (new PointF (566, 406));
theAnimation.TimingFunction = new CAMediaTimingFunction (0.25f ,0.1f ,0.25f ,1.0f);
view.Layer.AddAnimation (theAnimation, "animateLabel");
}
You can look at the source code for TweetStation’s “swipe” cell support, which performs varios animations at once:
All of those are done in a single transaction. The source code is in:
https://github.com/migueldeicaza/TweetStation/blob/06e2ae5484103a85660201592bd7f06fb1b69395/TweetStation/UI/SwipeSupport.cs
The animations are actually spread across various places. The SwipeMenuView configures its own animation (fading the icons into the background, growing/shrinking the icons) on its constructor and the animation is added to a CAAnimationGroup and the resulting animation is added to the layer, by using layer.AddAnimation (group):
A code snippet of this method is here:
The other part of the animation is configured in ShowMenu, that one swipes the cell out of the screen and if there was already a menu displayed, it animates the cell back bouncing it back to its new location:
ShowMenu triggers the animations by grouping the changes in a transaction block delimited by UIView.BeginAnimations () and UIView.CommitAnimations:
The menu animation is created to have a bouncing effect:
The AnimateBack method merely attaches the animation: