Birdkingz
Birdkingz

Reputation: 119

Translating a UIButton

I would like to ask is it possible to translate the UIButton position?

How? Anyone?

Upvotes: 0

Views: 425

Answers (1)

Hetal Vora
Hetal Vora

Reputation: 3361

You can get the frame of the button using "frame" property. This returns a CGRect object which basically has your buttons x-coord, y-coord, width and height.

Based on where you want to translate your button, calculate the new x-coord and y-coord. Then do the following:

btnMyButton.frame = CGRectMake(oldx,oldy,width,height);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:btnMyButton];
[UIView setAnimationDuration:0.3];  
btnMyButton.frame = CGRectMake(newx, newy, width, height);
[UIView commitAnimations];

Upvotes: 1

Related Questions