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 ...
随机推荐
- Hibernate关系映射(三) 多对多
一.使用用户User和Role实现多对多的示例 User.java,实现对Role的引用 package com.lxit.entity; import java.util.HashSet; impo ...
- Android Tint着色与帧动画结合
需求 最近遇到一个需求: 要求根据后台接口给的色值 显示不同色值的帧动画(UI给了三张透明色的图) 正常的帧动画 是配置在xml里三张静态图片 然后加载一下就完事了现有的静态图片是透明的 还没有填充颜 ...
- 演示程序之打游戏 -- 慕司板IAP15
上位机和协议制定我的大学舍友(他的微博:http://weibo.com/lesshst? topnav=1&wvr=5&topsug=1)毕业前百忙之中使用Python花了一个下午完 ...
- 001-使用idea开发环境安装部署,npm工具栏,脚本运行
一.概述 参看官方文档:https://ant.design/docs/spec/introduce-cn 其中包含了设计价值观.设计原则.视觉.模式.可视化.动态等. 其中Ant Design 的 ...
- 解决windows server2003 64位操作系统上不能加载32位应用程序dll 的问题
[FileLoadException: Could not load file or assembly 'sapnco_utils, Version=3.0.0.42, Culture=neutral ...
- Json数组操作小记 及 JSON对象和字符串之间的相互转换
[{"productid":"1","sortindex":"2"},{"productid":&q ...
- 消息队列 概念 配合SpringBoot使用Demo
转http://www.jianshu.com/p/048e954dab40 概念: 分布式消息队列 ‘分布式消息队列’包含两个概念 一是‘消息队列’,二是‘分布式’ 那么就先看下消息队列的概念,和为 ...
- unity, StopAllCoroutines导致bug的解决办法
StopAllCoroutines有时候不用不行. 但只要一用,就可能导致无穷无尽的bug. 原因是StopAllCoroutines会将当前脚本中所有coroutines都停掉,而没法做到只停掉我们 ...
- PHP的session存储对PHP运行环境的影响
转于:http://hmw.iteye.com/blog/1704020 这个问题的引入是由于公司一个项目里需要使用单点登录的功能,为了方便起见,就使用redis来替换php默认的文件存储sessio ...
- linux命令小技巧
一:命令行里怎么往上翻页 Shift+PageUP|PageDown 二:分页显示文件内容则可以用less工具过滤,然后用方向键或PageUp/PageDown上下翻 less /etc/passwd ...