Autorotation and Autosizing
配置应用级别的旋转方向——Global Setting
方法:点击项目-General-Deployment-Device Orientation
It doesn’t necessarily mean that every view in your application will use all of the selected orientations; but if you’re going to support an orientation in any of your application’s views, that orientation must be selected here.
配置视图级别的旋转方向——Local Setting
方法:ViewController.m中
- (NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft);
}
同一个App的不同视图,旋转方向的限制可能不一样。只能在应用级别的旋转方向上限制更多,比如应用级别不支持Upside-down,视图级别也一定不行。
附,旋转方向:
- UIInterfaceOrientationMaskPortrait
- UIInterfaceOrientationMaskLandscapeLeft
- UIInterfaceOrientationMaskLandscapeRight
- UIInterfaceOrientationMaskPortraitUpsideDown
- UIInterfaceOrientationMaskLandscape
- UIInterfaceOrientationMaskAll
- UIInterfaceOrientationMaskAllButUpsideDown
旋转,横竖视图排版一样
添加四个角(1,2,5,6)的Label


全选四个角(1,2,5,6)的Label,选择Editor -> Resolve Auto Layout Issues -> Add Missing Constraints

添加中间(3,4)的Label,对齐

左中(3)Editor -> Align -> Vertical Center in Container

右中(4)Editor -> Resolve Auto Layout Issues -> Add Missing Constraints

(1,2)加背景颜色,调整它们的宽度(随便,不一定等宽)



(1,2) Editor -> Pin -> Horizontal Spacing(无论怎么旋转都不等宽)


(1,2) Editor -> Pin -> Widths Equally(无论怎么旋转都等宽)


旋转,横竖视图排版不一样
创建SingleViewApplication,在View的File Inspector中取消AutoLayout,我们要利用代码实现布局。
在Main.storyboard中拖入一个View和4个Button,并设置该View的背景颜色。

ViewController.m中实现代码
旋转的时候就自动调用
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[self adjustLayout:toInterfaceOrientation];
}
- (void)adjustLayout:(UIInterfaceOrientation)toInterfaceOrientation
{
if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation))
{
[self layoutPortrait];
}
else
{
[self layoutLandscape];
}
}
static const CGFloat btnHeight = ;
static const CGFloat btnWidth = ;
static const CGFloat spacing = ; - (void)layoutPortrait
{
CGRect b = self.view.bounds;
CGFloat contentHeight = CGRectGetHeight(b)-btnHeight*-spacing*;
CGFloat contentWidth = CGRectGetWidth(b) - spacing*;
self.contentView.frame = CGRectMake(spacing, spacing, contentWidth, contentHeight); CGFloat btn1x = spacing;
CGFloat btn2x = CGRectGetWidth(b)-spacing-btnWidth;
CGFloat btn1y = contentHeight+*spacing;
CGFloat btn2y = btn1y+btnHeight+spacing; self.btn1.frame = CGRectMake(btn1x, btn1y, btnWidth, btnHeight);
self.btn2.frame = CGRectMake(btn2x, btn1y, btnWidth, btnHeight);
self.btn3.frame = CGRectMake(btn1x, btn2y, btnWidth, btnHeight);
self.btn4.frame = CGRectMake(btn2x, btn2y, btnWidth, btnHeight);
} - (void)layoutLandscape
{
CGRect b = self.view.bounds;
CGFloat contentHeight = CGRectGetHeight(b)-spacing*;
CGFloat contentWidth = CGRectGetWidth(b) - spacing*-btnWidth;
self.contentView.frame = CGRectMake(spacing, spacing, contentWidth, contentHeight); CGFloat btnx = CGRectGetWidth(b)-spacing-btnWidth;
CGFloat btny1 = spacing;
CGFloat btny4 = CGRectGetHeight(b)-spacing-btnHeight;
CGFloat btny2 = btny1+(btny4-btny1)/3.0;
CGFloat btny3 = btny2+(btny4-btny1)/3.0; self.btn1.frame = CGRectMake(btnx, btny1, btnWidth, btnHeight);
self.btn2.frame = CGRectMake(btnx, btny2, btnWidth, btnHeight);
self.btn3.frame = CGRectMake(btnx, btny3, btnWidth, btnHeight);
self.btn4.frame = CGRectMake(btnx, btny4, btnWidth, btnHeight);
}
viewDidLoad只在程序启动时调用了一次;屏幕旋转的时候没有调用它,调用的是- (void)willAnimateRotationToInterfaceOrientation:duration:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//处理启动时不是默认竖屏的情况。
UIApplication *app = [UIApplication sharedApplication];
UIInterfaceOrientation currentOrientation = app.statusBarOrientation;
[self adjustLayout:currentOrientation];
}
效果


Autorotation and Autosizing的更多相关文章
- 从零开始学ios开发(八):Autorotation and Autosizing
不好意思,这一篇间隔的时间有点长,最近实在是事情太多,耽搁了,好了,长话短说,下面继续学习ios. 这次学习的内容是Autorotation和Autosizing,Autorotation就是屏幕内容 ...
- 【 Beginning iOS 7 Development《精通iOS7开发》】05 Autorotation and Autosizing
一.旋转后相对位置不变 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZ29nbGVy/font/5a6L5L2T/fontsize/400/fill/I0 ...
- iOS iphone5屏幕适配 autosizing
转自:http://blog.sina.com.cn/s/blog_a843a8850101jxhh.html iphone5出来了,从不用适配的我们也要像android一样适配不同分辨率的屏幕了. ...
- xcode中没有autoSizing的设置
转自:http://blog.sina.com.cn/s/blog_954bb2f001016oyx.html 学习Xcode的iOS编程时,可能会发现Autosizing Control不见了,其原 ...
- Xcode无法设置视图的 autosizing control原因
转自:Xcode无法设置视图的 autosizing control原因 学习Xcode的iOS编程时,可能会发现Autosizing Control不见了,其原因很简单,因为你在设置中选择了Auto ...
- Android Oreo 8.0 新特性实战 Autosizing TextView --自动缩放TextView
Android Oreo 8.0 新特性实战 Autosizing TextView --自动缩放TextView 8.0出来很久了,这个新特性已经用了很久了,但是一直没有亲自去试试.这几天新的需求来 ...
- TextView 的新特性,Autosizing 到底是如何实现的? | 源码分析
一.前言 Hi,大家好,我是承香墨影! 前两天聊了一下 Autosizing 的使用,反映还不错.毕竟是这种能解决实际问题的新 Api,确实在需要的时候,用起来会很顺手. 简单回顾一下,Autosiz ...
- Android Autosizing TextViews
https://developer.android.com/guide/topics/ui/look-and-feel/autosizing-textview Autosizing TextView ...
- iOS Programming Autorotation, Popover Controllers, and Modal View Controllers
iOS Programming Autorotation, Popover Controllers, and Modal View Controllers 自动旋转,Popover 控制器,Moda ...
随机推荐
- webDriver API——第12部分WebElement
class selenium.webdriver.remote.webelement.WebElement(parent, id_) Bases: object Represents a DOM el ...
- html 里面的 role 属性是什么意思
role="button" role是什么意思? html 里面的 role 属性是什么意义和用途 使用role属性告诉辅助设备(如屏幕阅读器)这个元素所扮演的角色,属于WAI-A ...
- 【VBA编程】09.使用Excle集合对象
使用Workbooks工作簿集合.工作簿对象.工作表集合.工作表对象,并且观察使用Add方法前后工作簿与工作表数目的变化 [代码区域] Sub 测试集合工作簿() Dim wbs As Workboo ...
- 记一则Linux病毒的处理
今天某项目经理反馈学校的某台服务器不停的向外发包,且CPU持续100%,远程登录后查看发现有一长度为10的随机字符串进程,kill掉,会重新生成另外长度为10的字符串进程.删除文件也会重复生成,非常痛 ...
- 安装 Tomcat
安装 Tomcat(.exe) 而 .rar文件则只需解压即可使用. 点击 apache-tomcat-7.0.55.exe 进行安装: 在“Configuration”: Server Shutd ...
- Android studio 使用心得(一)—android studio快速掌握快捷键
大家都是从eclipse转过来了,所以早就熟悉了eclipse那一套快捷键. File—>settings—>keymap–>选择eclipse就搞定 话是这么说,但是自动化提示的变 ...
- Springboot接收参数
接收参数有三个方法. 1.接收id的方法: @RestController public class ControllerTest { //在这里读取配置文件 @Autowired private T ...
- HDU 5303 Delicious Apples(思维题)
Delicious Apples Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Other ...
- 关闭了的SQL Server服务如何打开
在cmd里输入如下:net start mssqlserver
- Sublime Text 2/3如何支持中文GBK编码(亲测实现)
Sublime Text 2/3如何支持中文GBK编码 听语音 | 浏览:17594 | 更新:2014-03-17 10:52 1 2 3 4 5 分步阅读 Sublime Text默认是只支持UT ...