UIView的AutoSizing
来源:互联网 发布:三金西瓜霜漱口水 知乎 编辑:程序博客网 时间:2024/06/03 19:24
若app支持旋转(rotation),那么几乎一定会涉及UIView的Autosizing问题。
Autosize有2种方法:
一是在NB的size inspectator property panel里设置;
一是用代码设置uiview的autoresizingMask属性;
注意: 对于margin,在NB里的设置和用代码设置逻辑上是相反的。
例子:
①要uiview基于屏幕左上角 (top & left) 的位置不变,
如果要代码则应该是
subView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin |UIViewAutoresizingFlexibleRightMargin;
而对应的NB设置则是:
②要uiview对于上下左右的margin都是flexible的 (即rotate时上下左右都要调整margin)
如果要代码则应该是
subView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
而对应的NB设置则是:
③要uiview对于上下左右的margin都是fix的 (如果你希望uiview旋转时不需要autosizing,即手动写代码来设置位置和大小,那么应该使用这个)
如果要代码则应该是
subView.autoresizingMask = UIViewAutoresizingNone;
而对应的NB设置则是:
配合上面的设置,你可能还需要手动写代码来设置uiview的位置和大小,example
view1.frame=CGRectMake(10,10, 100, 100);
建议uiview frame的设置的代码写在willAnimateRotationToInterfaceOrientation里 ,而shouldAutorotateToInterfaceOrientation方法则是用于设置支持哪些方向的rotation.
注意:willAnimateRotationToInterfaceOrientation在启动app时不会调用,只有在rotation之后才会调用,而shouldAutorotateToInterfaceOrientation在启动时也会调用,而且会调用超过一次!
Example:
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
- {
- NSLog(@"shouldAutorotateToInterfaceOrientation");
- return YES;
- }
- - (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
- NSLog(@"willAnimateRotationToInterfaceOrientation");
- if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
- toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
- {
- view1.frame=CGRectMake(10, 10, 100, 100);
- }
- else
- {
- view1.frame=CGRectMake(50, 50, 50, 50);
- }
- }
- UIView的AutoSizing
- Xcode无法设置视图的 autosizing control原因
- 新版本Xcode无法找到Autosizing和Example的解决方法
- xib中autosizing的用法(可适配ip5)
- iOS: autosizing
- iOS: autosizing
- iOS: autosizing
- iOS: autosizing
- iOS: autosizing
- UIView-draggable 可拖拽的UIView
- UIView-draggable 可拖拽的UIView
- Android O —— Autosizing TextViews 自动调整文本大小的TextView
- APP开发实战177-Autosizing TextViews(自动调整文字大小的TextViews)
- iOS AutoLayout与AutoSizing
- UIView的drawRect
- UIView的剖析!
- 第三、UIView的详解
- UIView的学习
- 浙大PAT advanced level 1003 emergency
- 内存管理之虚拟内存篇
- HDU 4165 Pills (dp解法)
- __asm__ __volatile__("": : :"memory")等系列问题
- ZOJ 1364 Machine Schedule
- UIView的AutoSizing
- 51单片机入门~chapter1
- 计算机网络基础
- w_文件流,缓冲流,二进制流复制文件哪个比较快!
- hdu 4746 Bell 中国剩余定理+矩阵乘法+第二类斯特林数 (2013网络赛)
- Linux Power Management for x86 CPU (1)---- C-State
- system32里的文件说明
- android小程序,根据生日年份计算出生肖
- C++/C功能程序代码