Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening a curtain: Animation with Core Animation

I would like to animate a curtain, which gets opened. I have two images: one for the left and one for the right side of the curtain (depicted in red). I would like to smoothly slide them away with Core Animation. For what animation type should I look for? How do I achieve a realistic sliding style?

Regards,

Stefan

alt text http://img.skitch.com/20100627-8ytxrbe64ccbruj49c2pbs7kt2.png

like image 581
Stefan Avatar asked Jun 27 '10 17:06

Stefan


2 Answers

I'm not sure why people are suggesting using a translation. If all you need to do is slide the images, simply call -setCenter on each image view inside an animation block. Like this:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[leftCurtainImageView setCenter:pointOffScreenLeft];
[rightCurtainImageView setCenter:pointOffScreenRight];
[UIView commitAnimations];

Where pointOffScreenLeft, and pointOffScreenRight are calculated something like:

CGPoint pointOffScreenLeft = CGPointMake(
                 -[leftCurtainImageView bounds].size.width, 
                 [leftCurtainImageView frame].origin.y);

CGPoint pointOffScreenRight = CGPointMake(
                 [rightCurtainImageView frame].origin.x + 
                 [rightCurtainImageView bounds].size.width, 
                 [leftCurtainImageView frame].origin.y);

These calculations assume that the curtains are positioned at the far left and far right edges respectively of their containing view.

like image 125
Matt Long Avatar answered Sep 27 '22 17:09

Matt Long


The easiest solution would be to have to imageview or CGLayers and then use CGAffineTransformTranslate in an animation block to slide them off screen.

like image 39
TechZen Avatar answered Sep 27 '22 16:09

TechZen