您的位置:首页 > 产品设计 > UI/UE

UI控件的位置操作

2014-02-05 12:22 459 查看
在一个UI控制器中先有一个大的VIEW,我们可以通过[self.view
subviews]获取控制器上所有的子组件,而组件的位置参照物都是父控件。我们常用到的修改组件的位置属性有frame、bounds、bounds、transform,值得注意的是,这些属性都是结构体,而苹果不允许我们直接修改属性结构体里面成员的值,一般都需要先取出来这个结构体,对这个结构体修改,再把结构体赋值给原来的属性,并且bounds属性的横纵坐标是相对于组件自己来说,所以bounds属性中的横纵坐标永远都是(0,0),在API中我们可以看到用了一个分类对UIView进行了扩展。

主要属性在分类中做了扩展

@interfaceUIView(UIViewGeometry)
 // animatable. do not use frame if view is transformedsince it will not correctly reflect the actual location of the view. use bounds+ center instead.
@property(nonatomic) CGRect            frame; //(横坐标,纵坐标,宽,高)
// use bounds/center and not frame if non-identitytransform. if bounds dimension is odd, center may be have fractional part
@property(nonatomic) CGRect            bounds;     
//(0,0,宽,高)
@property(nonatomic) CGPoint          
center;     
//(横坐标,纵坐标)
@property(nonatomic)
CGAffineTransform transform;  //旋转 缩放

引用一张苹果官方的图片对各个属性的说明



常见的赋值修改位置操作

CGRect frame=superView.frame;
frame.origin.x=self.view.frame.size.width;
superView.frame=frame;

//superView.frame.origin.x=10;  这句编译器会不通过不能直接修改结构体的内部的成员的值
也可以用以下方式修改

btn.frame=(CGRect){ponit,normalImage.size};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息