一、旋转后相对位置不变

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









最新文章

  1. JavaScript BOM对象介绍
  2. iOS 发布遇到的问题 (转载)
  3. Cisco IOS IP Service Level Agreementv (IP SLA)
  4. 无状态Web应用集成——《跟我学Shiro》
  5. Android 打包签名 从生成keystore到完成签名 -- 转
  6. Objective-C中Block语法、Block使用以及通过Block实现数组排序
  7. .NET 压缩解压库发布,支持进度查看
  8. Android开发中常见的设计模式
  9. opencv 小程序170323
  10. spring boot系列01--快速构建spring boot项目
  11. 微软Telnet的回显功能开启
  12. 快速构建SPA框架SalutJS--项目工程目录 二
  13. Petrozavodsk Summer-2017. Moscow IPT Contest
  14. Scala - 快速学习07 - 模式匹配
  15. 如何修改discuz论坛的图像地址
  16. 从零开始学 Web 之 ES6(三)ES6基础语法一
  17. python 入门练习
  18. automation轻松“一点”,搞定裸机安装系统
  19. 【转】一个简单的WCF回调实例
  20. idea 常用快捷键 笔记

热门文章

  1. shell-3.bash的基本功能: history tab alias 快捷键
  2. 我的Java历程_Java对象类型的转换
  3. html5学习之第一步:认识标签,了解布局
  4. Webpack的作用(一个基础的打包编译工具在做什么?)
  5. mac终端安装webpack的时候报错Err,解决的办法 sudo npm install webpack -g
  6. BZOJ 1195 [HNOI2006]最短母串 (Trie图+状压+bfs最短路)
  7. 《virtual san 最佳实践》节选 Virtual SAN的发展与现状
  8. /etc/rsyncd.conf
  9. git checkout -b 报错
  10. hadoop学习;datajoin;chain签名;combine()