Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animation : How to make UIbutton move from right to left when view is loaded?

I have not done any animation stuff with iphone development so far.

Can anybody help me how to make UIbutton move from right to left when view is loaded?

I want to generate effect like that : when view is loaded, the button appears moving from right end to left & stops at its place. Is it possible?

Any help regarding this animation stuff is appreciated. Please help with some sample if available.

Thanks in advance.

like image 925
Rambo Avatar asked Nov 04 '09 06:11

Rambo


3 Answers

Just to make it even slicker, I would suggest not changing the UIView's frame but its center;

CGPoint newLeftCenter = CGPointMake( 20.0f + myButton.frame.size.width / 2.0f, myButton.center.y);
[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:1.0f];
myButton.center = newLeftCenter;
[UIView commitAnimations];
like image 164
Till Avatar answered Nov 13 '22 09:11

Till


in your viewDidAppear:(BOOL)animated method you can change frame of your button inside animation block. so you'll see what you want. Check documentation about animations in UIView class reference. The simpliest animation block will be like that(sorry, i have no mac nearby right now, so code may not be working just after copy and paste)

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0f];
[myButton setFrame:newFrame];
[UIView commitAnimations];
like image 36
Morion Avatar answered Nov 13 '22 11:11

Morion


From top to bottom animation

CATransition *animation = [CATransition animation];
[animation setDuration:0.4];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromBottom];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[TopButton layer] addAnimation:animation forKey:@"SwitchToDown"];
like image 1
Manikandan Avatar answered Nov 13 '22 09:11

Manikandan