【 Beginning iOS 7 Development《精通iOS7开发》】05 Autorotation and Autosizing
一、旋转后相对位置不变
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZ29nbGVy/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZ29nbGVy/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZ29nbGVy/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
二、旋转后相对位置变化
2.1默认:
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZ29nbGVy/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
2.2调整后
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZ29nbGVy/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
三、小结
3.1 在APP级别设置支持哪些方向:
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZ29nbGVy/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
3.2 在viewController(xlib)级别设置支持哪些方向:
#import "JAViewController.h" @interface JAViewController () @end @implementation JAViewController - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} //重写这种方法
-(NSUInteger)supportedInterfaceOrientations
{
// return (UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskPortraitUpsideDown);
// return UIInterfaceOrientationMaskAll;
return (UIInterfaceOrientationMaskLandscapeRight|UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskPortraitUpsideDown);
} @end
3.3 使用约束Contstraints
3.4 当上面的Contraints办法满足不了时,关闭掉它,让后在ViewController.m中通过代码实现。
//
// JAViewController.m
// Restructure
//
// Created by jason on 14-7-16.
// Copyright (c) 2014年 jason. All rights reserved.
// #import "JAViewController.h" @interface JAViewController ()
@property (weak, nonatomic) IBOutlet UIButton *actionButton1;
@property (weak, nonatomic) IBOutlet UIButton *actionButton2;
@property (weak, nonatomic) IBOutlet UIButton *actionButton3;
@property (weak, nonatomic) IBOutlet UIButton *actionButton4;
@property (weak, nonatomic) IBOutlet UIView *contentView; @end @implementation JAViewController - (void)viewDidLoad
{
[super viewDidLoad];
// 从这里開始
UIApplication *app = [UIApplication sharedApplication];
UIInterfaceOrientation currentOrientation = app.statusBarOrientation;
[self doLayoutForOrientation:currentOrientation];//跳转到实际处理处
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} //从这里開始
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[self doLayoutForOrientation:toInterfaceOrientation];
} //确定当前方向
-(void)doLayoutForOrientation:(UIInterfaceOrientation)orientation
{
if (UIInterfaceOrientationIsPortrait(orientation)) {
[self layoutPortrait];
} else {
[self layoutLandscape];
}
} static const CGFloat buttonHeight = 40;
static const CGFloat buttonWidth = 120;
static const CGFloat spacing = 20; //竖向处理
- (void)layoutPortrait {
CGRect b = self.view.bounds;
CGFloat contentWidth = CGRectGetWidth(b) - (2 * spacing);
CGFloat contentHeight = CGRectGetHeight(b) - (4 * spacing) -
(2 * buttonHeight);
self.contentView.frame = CGRectMake(spacing, spacing,
contentWidth, contentHeight);
CGFloat buttonRow1y = contentHeight + (2 * spacing);
CGFloat buttonRow2y = buttonRow1y + buttonHeight + spacing;
CGFloat buttonCol1x = spacing;
CGFloat buttonCol2x = CGRectGetWidth(b) - buttonWidth - spacing;
self.actionButton1.frame = CGRectMake(buttonCol1x, buttonRow1y,
buttonWidth, buttonHeight);
self.actionButton2.frame = CGRectMake(buttonCol2x, buttonRow1y,
buttonWidth, buttonHeight);
self.actionButton3.frame = CGRectMake(buttonCol1x, buttonRow2y,
buttonWidth, buttonHeight);
self.actionButton4.frame = CGRectMake(buttonCol2x, buttonRow2y,
buttonWidth, buttonHeight);
} //横向处理
- (void)layoutLandscape {
CGRect b = self.view.bounds;
CGFloat contentWidth = CGRectGetWidth(b) - buttonWidth - (3 * spacing);
CGFloat contentHeight = CGRectGetHeight(b) - (2 * spacing);
self.contentView.frame = CGRectMake(spacing, spacing,
contentWidth, contentHeight);
CGFloat buttonX = CGRectGetWidth(b) - buttonWidth - spacing;
CGFloat buttonRow1y = spacing;
CGFloat buttonRow4y = CGRectGetHeight(b) - buttonHeight - spacing;
CGFloat buttonRow2y = buttonRow1y + floor((buttonRow4y - buttonRow1y)
* 0.333);
CGFloat buttonRow3y = buttonRow1y + floor((buttonRow4y - buttonRow1y)
* 0.667);
self.actionButton1.frame = CGRectMake(buttonX, buttonRow1y,
buttonWidth, buttonHeight);
self.actionButton2.frame = CGRectMake(buttonX, buttonRow2y,
buttonWidth, buttonHeight);
self.actionButton3.frame = CGRectMake(buttonX, buttonRow3y,
buttonWidth, buttonHeight);
self.actionButton4.frame = CGRectMake(buttonX, buttonRow4y,
buttonWidth, buttonHeight);
} @end
【 Beginning iOS 7 Development《精通iOS7开发》】05 Autorotation and Autosizing的更多相关文章
- 翻译Beginning iOS 7 Development中文版
不会iOS开发好像真的说只是去,来本中文版的Beginning iOS 7 Development吧. 看了Beginning iOS 7 Development这本书,感觉蛮不错的.全英文的,没有中 ...
- 从零开始学ios开发(八):Autorotation and Autosizing
不好意思,这一篇间隔的时间有点长,最近实在是事情太多,耽搁了,好了,长话短说,下面继续学习ios. 这次学习的内容是Autorotation和Autosizing,Autorotation就是屏幕内容 ...
- 开始翻译《Beginning SharePoint 2013 Development》
伙同涂曙光@kaneboy 和柴晓伟@WindieChai 翻译Beginning SharePoint 2013 Development 作者是Steve Fox,传说中的Andrew Connel ...
- iOS应用内付费(IAP)开发步骤列表
iOS应用内付费(IAP)开发步骤列表 前两天和服务端同事一起,完成了应用内付费(以下简称IAP, In app purchase)的开发工作.步骤繁多,在此把开发步骤列表整理如下.因为只是步骤列表, ...
- IOS7开发~新UI学起(一)
本文转载至:http://blog.csdn.net/lizhongfu2013/article/details/9124893 IOS7在UI方面发生了很大改变,所以感觉有必要重新审视的学习一下(新 ...
- iOS 移动端生成工具开发
代码地址如下:http://www.demodashi.com/demo/11284.html 一.准备工作 编译环境 xcode 用于生成冗余架构代码, 实现生成零耦合架构 二.程序实现 上个月的一 ...
- iOS UITableViewCell UITableVIewController 纯代码开发
iOS UITableViewCell UITableVIewController 纯代码开发 <原创> .纯代码 自定义UITableViewCell 直接上代码 ////// #imp ...
- iOS Mobile Development: Using Xcode Targets to Reuse the Code 使用xcode targets来实现代码复用
In the context of iOS mobile app development, a clone is simply an app that is based off another mob ...
- Beginning iOS Programming
Beginning iOS Programming 2014年 published by Wrox
随机推荐
- vue项目input的placeholder根据用户的选择改变
html部分 <el-input :placeholder="holder" v-model="searchKey"> <el-select ...
- 洛谷2055 [ZJOI2009]假期的宿舍
题目描述 学校放假了 · · · · · · 有些同学回家了,而有些同学则有以前的好朋友来探访,那么住宿就是一个问题.比如 A 和 B 都是学校的学生,A 要回家,而 C 来看B,C 与 A 不认识. ...
- [HDU5688]2016"百度之星" - 资格赛 Problem D
题目大意:给你n个字符串,如果一个字符串可以通过重新排列变成另一个字符串,则认为这两个字符串相等.每输入一个字符串,输出这个字符串和与它相等的之前出现了几次. 解题思路:我们可以用map保存一个字符串 ...
- nodejs 守护进程运行
有四种方法: 1.forever forver start bin/www 2.pm2 pm2 strat bin/www 3.node自身进程保护 nohup node /bin/www > ...
- mysql同步复制报Slave can not handle replication events with the checksum that master 错误
slave服务器,查看状态时,发现下面的错误: Last_IO_Error: Got fatal error 1236 from master when reading data from binar ...
- POJ 1741 Tree 树的分治(点分治)
题目大意:给出一颗无根树和每条边的权值,求出树上两个点之间距离<=k的点的对数. 思路:树的点分治.利用递归和求树的重心来解决这类问题.由于满足题意的点对一共仅仅有两种: 1.在以该节点的子树中 ...
- [Android Studio 权威教程]配置出“NB”的Android Studio
前几篇博客我们已经安装好了As,并且创建了我们的第一个HelloWrod ,这片blog我们继续配置出一个NB的Android Studio 假设你是一个才開始接触到AS或者想从Eclipse转型到A ...
- hdu 5318 The Goddess Of The Moon 矩阵高速幂
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5318 The Goddess Of The Moon Time Limit: 6000/3000 MS ( ...
- less03 混合
less //基本混合 .font_hn{ color: red; font-family: microsoft yahei, "黑体", Arial, Simsun, " ...
- 木马——本质就是cs socket远程控制,反弹木马是作为c端向外发起网络请求
摘自:http://kczxsp.hnu.edu.cn/upload/20150504165623705.pdf 里面对于木马的实验过程写得非常清楚,值得一看. 木马是隐藏在正常程序中的具有特殊功 ...