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 ...
随机推荐
- java开发中的一些概念名词
1. JavaBeans JavaBean是符合某种规范的Java组件,也就是Java类.它必须满足如下规范: 1)必须有一个零参数的默认构造函数 2)必须有get和set方法,类的字段必须通过get ...
- Sun公司开源游戏服务器
http://www.360doc.com/content/11/0307/12/2902158_98866885.shtml http://www.cnblogs.com/daidu/archive ...
- windows下检測软件的网络连接
首先打开任务管理器选中你要查看的应用.右键转到进程 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZGFwZW5nMDExMg==/font/5a6L5L2 ...
- js 获取当前时间并格式化
js 获取当前时间并格式化 CreateTime--2018年2月7日11:04:16 Author:Marydon 方式一 /** * 获取系统当前时间并格式化 * @returns yyyy- ...
- Visual studio之C# 串口通讯SerialPort
背景 App需要串口进行通讯,在此做个记录和简要说明. 正文 添加命名空间 using System.IO.Ports; 实例化串口 SerialPort serialPortO = new Seri ...
- JDBC数据库编程:callableStatement接口
了解MySQL存储过程建立, 了解存储过程中参数传递的三种方式 了解callablestatement调用存储过程操作. 因为在现在开发中,使用存储过程的地方越来越少,所以,对于存储过程使用,只需要了 ...
- Linux的定时器
在服务端程序设计中,与时间有关的常见任务有: 获取当前时间,计算时间间隔: 定时操作,比如在预定的时间执行一项任务,或者在一段延时之后执行一项任务. Linux 时间函数 Linux 的计时函数,用于 ...
- Tomcat_启动参数设置
1.修改启动时内存参数.并指定JVM时区 (在windows server 2008 下时间少了8个小时): 在Tomcat上运行j2ee项目代码时,经常会出现内存溢出的情况,解决办法是在系统参数中增 ...
- 事件总线框架---Otto
我们假设这样一种业务场景,现在在做一款及时聊天应用,我们在聊天页面进行收发信息,同时也要实时更新前一页面的聊天记录,这时我们该如何去实现?说说我以前的实现策略,我使用的是广播接收器BroadCastR ...
- Linux Load average负载详细解释
http://tianmaotalk.iteye.com/blog/1027970 Linux Load average负载详细解释 linux查看机器负载