翻译UIButton [英] Translating a UIButton

查看:36
本文介绍了翻译UIButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问问是否可以平移UIButton的位置?

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

如何?有人吗?

推荐答案

您可以使用"frame"属性获取按钮的框架.这将返回一个CGRect对象,该对象基本上具有按钮x坐标,y坐标,宽度和高度.

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.

根据您要翻译按钮的位置,计算新的x坐标和y坐标. 然后执行以下操作:

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

这篇关于翻译UIButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆