一、旋转后相对位置不变

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的更多相关文章

  1. 翻译Beginning iOS 7 Development中文版

    不会iOS开发好像真的说只是去,来本中文版的Beginning iOS 7 Development吧. 看了Beginning iOS 7 Development这本书,感觉蛮不错的.全英文的,没有中 ...

  2. 从零开始学ios开发(八):Autorotation and Autosizing

    不好意思,这一篇间隔的时间有点长,最近实在是事情太多,耽搁了,好了,长话短说,下面继续学习ios. 这次学习的内容是Autorotation和Autosizing,Autorotation就是屏幕内容 ...

  3. 开始翻译《Beginning SharePoint 2013 Development》

    伙同涂曙光@kaneboy 和柴晓伟@WindieChai 翻译Beginning SharePoint 2013 Development 作者是Steve Fox,传说中的Andrew Connel ...

  4. iOS应用内付费(IAP)开发步骤列表

    iOS应用内付费(IAP)开发步骤列表 前两天和服务端同事一起,完成了应用内付费(以下简称IAP, In app purchase)的开发工作.步骤繁多,在此把开发步骤列表整理如下.因为只是步骤列表, ...

  5. IOS7开发~新UI学起(一)

    本文转载至:http://blog.csdn.net/lizhongfu2013/article/details/9124893 IOS7在UI方面发生了很大改变,所以感觉有必要重新审视的学习一下(新 ...

  6. iOS 移动端生成工具开发

    代码地址如下:http://www.demodashi.com/demo/11284.html 一.准备工作 编译环境 xcode 用于生成冗余架构代码, 实现生成零耦合架构 二.程序实现 上个月的一 ...

  7. iOS UITableViewCell UITableVIewController 纯代码开发

    iOS UITableViewCell UITableVIewController 纯代码开发 <原创> .纯代码 自定义UITableViewCell 直接上代码 ////// #imp ...

  8. 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 ...

  9. Beginning iOS Programming

    Beginning iOS Programming 2014年 published by Wrox

随机推荐

  1. H5中嵌入flash

    <object height="900px" width="100%" classid="clsid:D27CDB6E-AE6D-11cf-96 ...

  2. Quartz任务调度 服务日志+log4net打印日志+制作windows服务

    引言 现在许多的项目都需要定时的服务进行支撑,而我们经常用到的定时服务就是Quartz任务调度了.不过我们在使用定时Job进行获取的时候,有时候我们就需要记录一下自定义的日志,甚至我们还会对执行定时J ...

  3. KMP笔记

    KMP #include<iostream> #include<cstring> #include<cstdio> #include<cmath> us ...

  4. POJ-1743 Musical Theme 字符串问题 不重叠最长重复子串

    题目链接:https://cn.vjudge.net/problem/POJ-1743 题意 给一串整数,问最长不可重叠最长重复子串有多长 注意这里匹配的意思是匹配串的所有元素可以减去或者加上某个值 ...

  5. LightOJ-1336 Sigma Function 唯一分解定理 巧妙使用sqrt()等算数目

    题目链接:https://cn.vjudge.net/problem/LightOJ-1336 题意 给出一个区间[1, n],求区间内所有数中因数之和为偶数的数目 思路 第二次写这个题 首先想到唯一 ...

  6. 【hackerrank week of code 26】Hard Homework

    [题目链接]:https://www.hackerrank.com/contests/w26/challenges/hard-homework/problem [题意] 给你一个式子:sin(x)+s ...

  7. [android] 百度地图开发 (一).申请AK显示地图及解决显示空白网格问题

        近期做android百度地图,可是使用baidumapapi_v2_3_1.jar和libBaiduMapSDK_v2_3_1.so显示百度地图时总是遇到问题--仅仅显示网格而没有显示地图,网 ...

  8. hadoop学习;datajoin;chain签名;combine()

    hadoop有种简化机制来管理job和control的非线性作业之间的依赖.job对象时mapreduce的表现形式.job对象的实例化可通过传递一个jobconf对象到作业的构造函数中来实现. x. ...

  9. TCP/IP、UDP、 Http、Socket的差别

    网络由上往下分为: 表示层和应用层 :HTTP协议(基于传输层的TCP协议,主要解决怎样包装数据) 会话层 传输层: TCP协议(基于网络层的IP协议).TPC/IP协议(主要解决数据怎样在网络中传输 ...

  10. MongoDB学习笔记&lt;七&gt;

    继续MongoDB的学习 1.导出数据(中断其它操作) 把数据库test中的books集合导出 在终端下进行操作 mongoexport -d test -c books -o /home/hadoo ...