A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

[size=2.2em]Creating a View
自己翻译的苹果API文档,感觉会比每天读英文单词进步大些,其实最好的方法还是在工作中遇到问题了,然后去API中查看,可能理解和记忆的才会更加深入,希望自己能够坚持下来,在休息的同时顺便多多阅读官方文档
To create a view programmatically, you can use code like the following:
CGRect  viewRect = CGRectMake(10, 10, 100, 100);UIView* myView = [[UIView alloc] initWithFrame:viewRect];
This code creates the view and positions it at the point (10, 10) in its superview’s coordinate system (once it is added to that superview). To add a subview to another view, you use the addSubview: method. In iOS, sibling views may overlap each other without any issues, allowing complex view placement. The addSubview: method places the specified view on top of other siblings. You can specify the relative z-order of a subview by adding it using the insertSubview:aboveSubview: and insertSubview:belowSubview: methods. You can also exchange the position of already added subviews using the exchangeSubviewAtIndex:withSubviewAtIndex: method.
When creating a view, it is important to assign an appropriate value to the autoresizingMask property to ensure the view resizes correctly. View resizing primarily occurs when the orientation of your application’s interface changes but it may happen at other times as well. For example, calling the setNeedsLayout method forces your view to update its layout.
创建一个视图
创建一个视图程序你可能用以下代码:
CGRect viewRect = CGRectMake(10,10,100,100); UIView* myView = [[UIView alloc] initWithFrame:viewRect];
这段代码创建了这个视图的位置在点(10,10)在它的父视图坐标系统中(一旦它被添加到父视图)。给另一个视图增加子视图,你要用addSubview:方法。在IOS中,兄弟视图可以没有任何问题的彼此重叠,允许复杂的视图安置。这个addSubview:方法说明的视图在其他兄弟视图的顶层。你可以具体说明子视图与z轴的关系通过增加它用insertSubview:aboveSubview:和insertSubview:belowSubview:方法。你还可以交换已准备增加的子视图的位置用exchangeSubviewAtIndex:withSubviewAtIndex:方法。
当创建一个视图,它是重要的去分配一个合适的值到autoresizingMask属性去保证这个视图正确的大小。视图变化主要发生在当你的应用接口变化取向,但是它还可能发生在其他时候。例如,调用这个setNeedsLayout方法强制你的视图去更新它的布局。

1 个回复

倒序浏览
英语就是不断的学习和积累   每天多记相关的单词   每一个单词都可以拆分为2个或3各部分来记忆  
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马