【 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
随机推荐
- H5页面在线制作工具搜集
1.初页 http://chuye.cloud7.com.cn/ 2.易企秀 http://eqxiu.com/#/home 3.最酷 http://www.zuiku.com/ 4.易传单 http ...
- HBuilder 连接小米手机
(1)手机与电脑未用USB数据线连接(嘿嘿,这一部大家估计都做到了,可略过) (2)电脑上需要安装电脑版的手机助手,帮助手机顺利连接上(用安卓手机联调的话可安装360手机助手,若用iPhone的话可安 ...
- 入门python:《Python编程快速上手让繁琐工作自动化》中英文PDF+代码
入门推荐学习<python编程快速上手>前6章是python的基础知识,通俗易懂地讲解基础,初学者容易犯错的地方,都会指出来.从第三章开始,每章都有一个实践项目,用来巩固前面所学的知识. ...
- visio使用技巧
1.背景放大: 按住Ctrl键,滚动鼠标滚轮,即可调整背景大小,这是改变的显示比例 2.背景: 按住Ctrl+E,在背景边框处拖动图标,即可拉大或者缩小背景,这是实际更改背景大小.
- 【codeforces 466D】Increase Sequence
[题目链接]:http://codeforces.com/problemset/problem/466/D [题意] 给你n个数字; 让你选择若干个区间; 且这些区间[li,ri]; 左端点不能一样; ...
- CodeForces 445E DZY Loves Colors
DZY Loves Colors Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces ...
- hadoop-16-sqoop导入oracle数据
sqoop = sql + hadoop 1,系统方面的准备 scp ./ojdbc6.jar root@server-1:/usr/hdp/2.6.0.3-8/sqoop/lib/scp ./ojd ...
- HDU 4756 Install Air Conditioning(次小生成树)
题目大意:给你n个点然后让你求出去掉一条边之后所形成的最小生成树. 比較基础的次小生成树吧. ..先prime一遍求出最小生成树.在dfs求出次小生成树. Install Air Conditioni ...
- php通过shell调用Hadoop的方法
1.php代码(index.php) <!DOCTYPE html> <html> <!-- <style> body{background-color:re ...
- Dubbo分布式服务框架入门(附project)
要想了解Dubbo是什么,我们不防先了解它有什么用. 使用场景:比方我想开发一个网上商城项目.这个网上商城呢,比較复杂.分为pc端web管理后台.微信端销售公众号,那么我们分成四个项目,pc端站点,微 ...