简单的方法来改变UIView的位置? [英] Simple way to change the position of UIView?
本文介绍了简单的方法来改变UIView的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下代码更改UIView的位置,而不更改视图的大小。
I change the position of a UIView with following codes without changing size of the view.
CGRect f = aView.frame;
f.origin.x = 100; // new x
f.origin.y = 200; // new y
aView.frame = f;
是否有更简单的方法只更改视图位置?
Is there more simple way to change only the view position?
推荐答案
aView.center = CGPointMake(150, 150); // set center
或
aView.frame = CGRectMake( 100, 200, aView.frame.size.width, aView.frame.size.height ); // set new position exactly
或
aView.frame = CGRectOffset( aView.frame, 10, 10 ); // offset by an amount
编辑:
我还没有编译它,但它应该可以工作:
I didn't compile this yet, but it should work:
#define CGRectSetPos( r, x, y ) CGRectMake( x, y, r.size.width, r.size.height )
aView.frame = CGRectSetPos( aView.frame, 100, 200 );
这篇关于简单的方法来改变UIView的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文