我使用以下代码更改UIView的位置,而不更改视图的大小.
CGRect f = aView.frame;
f.origin.x = 100; // new x
f.origin.y = 200; // new y
aView.frame = f;
是否有更简单的方法只更改视图位置?
我使用以下代码更改UIView的位置,而不更改视图的大小.
CGRect f = aView.frame;
f.origin.x = 100; // new x
f.origin.y = 200; // new y
aView.frame = f;
是否有更简单的方法只更改视图位置?
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
Edit:个
I didn't compile this yet, but it should w或k:
#define CGRectSetPos( r, x, y ) CGRectMake( x, y, r.size.width, r.size.height )
aView.frame = CGRectSetPos( aView.frame, 100, 200 );