Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

chhoda

macrumors 6502
Original poster
Oct 25, 2008
285
1
Hi All,
I am asked to do a slide swapping animation kind of stuff. Are there any examples ? is it possible using core animation ? Actually in may main view i will have 2 subviews And i want to swap their positions with an animation on touch drag.

any pointers are welcome

--CH
 
so you just want to exchange the position of the two subviews, did I get that right? if so, that can be done even without Core Animation. UIView has some animation methods that allow you to animate changes to the frame and alpha and some other values of the view. see the docs of UIView for that.
basically, you start the animation block with "beginAnimations:context:", then you can set some animation properties with stuff like "setAnimationDuration:", then you simply tell the animation what you want to change, for example
subview1.frame = newPositionRect;
and then you fire the animation with "commitAnimations"

was that even what you wanted to know? :D

PS: afaik, this is also possible with core animation, but if you don't need it why make things complicated?
 
thanks

thanks for replying, yes thats what exactly i wanted, following piece of code worked. thanks for giving the ideas.

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:1];
CGRect btnOneFrame = [self.buttonOne frame];
CGRect btnTwoFrame = [self.buttonTwo frame];
[self.buttonOne setFrame:btnTwoFrame];
[self.buttonTwo setFrame:btnOneFrame];

[UIView commitAnimations];

-CH
 
note that it's getting kinda complicated when it is possible that an animation starts while an animation is running.
UIView has an "startAnimationFromCurrentState" property, but it never worked for me when I animated the position of a view. so you should make sure that two animations are not running at the same time on the same view.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.