5

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

Stefan
  • 28,843
  • 15
  • 64
  • 76

3 Answers3

5

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.

Matt Long
  • 24,438
  • 4
  • 73
  • 99
1

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

TechZen
  • 64,370
  • 15
  • 118
  • 145
0

Man

After a long search. The only way I could find is this.

https://github.com/Ciechan/BCMeshTransformView

jose920405
  • 7,982
  • 6
  • 45
  • 71