UI控件的位置操作
2014-02-05 12:22
459 查看
在一个UI控制器中先有一个大的VIEW,我们可以通过[self.view
subviews]获取控制器上所有的子组件,而组件的位置参照物都是父控件。我们常用到的修改组件的位置属性有frame、bounds、bounds、transform,值得注意的是,这些属性都是结构体,而苹果不允许我们直接修改属性结构体里面成员的值,一般都需要先取出来这个结构体,对这个结构体修改,再把结构体赋值给原来的属性,并且bounds属性的横纵坐标是相对于组件自己来说,所以bounds属性中的横纵坐标永远都是(0,0),在API中我们可以看到用了一个分类对UIView进行了扩展。
引用一张苹果官方的图片对各个属性的说明
常见的赋值修改位置操作
也可以用以下方式修改
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}; |
相关文章推荐
- iOS中调整UI控件位置和尺寸
- 多线程操作UI控件——DataGridView假死现象
- js 对表格的动态操作(动态添加行,删除该行,在指定位置添加控件)
- c# wpf下的多线程操作窗口UI控件的过程
- 背水一战 Windows 10 (72) - 控件(控件基类): UIElement - UIElement 的位置, UIElement 的布局, UIElement 的其他特性
- 黑马程序员--UI的基本控件使用之UILabel与UIButton的基本操作
- Qt 批量操作 UI 控件
- 如何使得控件不需要在操作UI时检查InvokeRequired
- textview中特定位置几个字设置其效果以及定时器(多长时间后执行什么操作)和控件设圆角 圆边线
- [WinForm]WinForm跨线程UI操作常用控件类大全
- Android-UI控件的绘制流程以及自定义控件的具体操作
- 针对需要频繁调整控件位置的客户端UI框架的构思
- c#非委托方式在子线程里操作UI控件(实际上运算逻辑在子线程,更新还是在主线程,解决了UI界面无响应的问题)
- 后台线程与UI线程问题:解决“线程间操作无效: 从不是创建控件xxx的线程访问它”
- js 对表格的动态操作(动态添加行,删除该行,在指定位置添加控件)
- IOS中调整UI控件位置和尺寸
- IOS UI简单的控件位置/尺寸/旋转变换
- android 解决 addView()操作之后,之前的控件位置重置的问题
- 使用BackgroundWorker在UI上操作主线程控件
- Operamasks-UI控件操作