Translating a UIButton

巧了我就是萌 提交于 2019-12-25 18:03:01

问题


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

How? Anyone?


回答1:


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];


来源:https://stackoverflow.com/questions/5613306/translating-a-uibutton

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!