竖屏情况下: [UIScreen mainScreen].bounds.size.width = 320

[UIScreen mainScreen].bounds.size.width = 568

横屏情况下:

[UIScreen mainScreen].bounds.size.width = 568

[UIScreen mainScreen].bounds.size.height = 320

UIViewController 和 UIWindow同理

1. storyboard iphone和 iPad版

即为iphone和ipad分别创建xib/storyboard文件

Main_iPhone.storyboard

Main_iPad.storyboard

横竖屏

苹果官方文档:

When the user changes the device orientation, the system calls this method on the root view controller or the topmost presented view controller that fills the window. If the view controller supports the new orientation, the window and view controller are rotated to the new orientation. This method is only called if the view controller'€™s shouldAutorotate method returns YES.

- (BOOL)shouldAutorotate

{   
  return YES;
} - (NSUInteger)supportedInterfaceOrientations {
  return UIInterfaceOrientationMaskAll;
}

注意要写在最顶层视图控制器, (self.window.rootViewController) , 否则不会进入以上方法

而且

supportedInterfaceOrientations的返回值必须是

UIInterfaceOrientationMaskLandscapeLeft 或者 UIInterfaceOrientationMaskLandscapeRight 或者...

总之必须加Mask

通知是当前线程异步

tabbarcontroller 为 根控制器的情况

- (BOOL)shouldAutorotate
{
return [self.selectedViewController shouldAutorotate];
} - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [self.selectedViewController preferredInterfaceOrientationForPresentation];
} - (NSUInteger)supportedInterfaceOrientations
{
return [self.selectedViewController supportedInterfaceOrientations];
}

navigationcontroller为根控制器的情况:

- (BOOL)shouldAutorotate
{
return [self.viewControllers.lastObject shouldAutorotate];
} - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [self.viewControllers.lastObject preferredInterfaceOrientationForPresentation];
} - (NSUInteger)supportedInterfaceOrientations
{
return [self.viewControllers.lastObject supportedInterfaceOrientations];
}

Iphone和iPad适配, 横竖屏的更多相关文章

  1. ios tableview 适配横竖屏

    tableview.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;

  2. 仿iPhone、iPad界面滑屏切换

    <!DOCTYPE html> <html lange='en'> <head> <meta charset='UTF-8'> <title> ...

  3. JS禁止横竖屏切换,强制横竖屏显示

    js判断屏幕横竖屏: function orient() { //alert('gete'); if (window.orientation == 0 || window.orientation == ...

  4. iPad横竖屏代码适配

    你可能非常了解用不同的方式去适配不同尺寸的iPhone屏幕,在适配iPhone屏幕时你需要考虑的只是屏幕大小变化带来的UI元素间隔的变化,但是在iPad上主要针对的是横竖屏下完全不同的UI元素的布局, ...

  5. 48 (OC)* 适配iPad和iPhone、以及横竖屏适配。

    一:核心方法 1.三个方法 1.1:开始就会触发 - (void)viewWillLayoutSubviews; 1.2:开始就会触发 - (void)viewDidLayoutSubviews; 1 ...

  6. ios5和ios6横竖屏支持及ipad和iphone设备的判断

    ios5和ios6横竖屏支持及ipad和iphone设备的判断 判断是ipad还是iphone设备.此定义在PayViewControllerDemo-Prefix.pch 定义如下: #define ...

  7. (一〇八)iPad开发之横竖屏适配

    在iPad开发中,横竖屏的视图常常是不同的,例如侧边栏Dock,在横屏时用于屏幕较宽,可以展示足够多的内容,每个按钮都可以展示出标题:而竖屏时Dock应该比较窄,只显示图标不现实按钮标题. iPad比 ...

  8. iOS 横竖屏适配

    关于横竖屏适配 也没做过,今天读别人的源码,遇到了.为了了解清楚,就系统的学习一下. 一 横竖屏方向枚举 关于横竖屏一共有三种枚举 UIInterfaceOrientation UIInterface ...

  9. 在Mac电脑上为iPhone或iPad录屏的方法

    在以前的Mac和iOS版本下,录制iPhone或者iPad屏幕操作是一件稍微复杂的事情.但是随着Yosemite的出现,在Mac电脑上为iPhone或iPad录屏的方法就变得简单了.下面就介绍一下具体 ...

随机推荐

  1. 记”Uri.IsWellFormedUriString”中的BUG

    场景 先上逻辑代码 1: /// <summary> 2: /// 图片真实地址 3: /// </summary> 4: public string FullImagePat ...

  2. 第四章:Javascript表达式和运算符

    表达式是javascript中的一个短语,javascript解释器会将其计算出一个结果.程序中常用量是最简单的一类表达式就是变量.变量名也是一种简单的表达式,它的值就是赋值给变量的值.复杂的表达式是 ...

  3. 写在读ng之前的基础知识----笔记

    如果要看angular的代码, 先把这个给看了, 司徒的干货. /******************************************************************* ...

  4. Web Service 小练习

    对于网站与网站之间数据互动,这是我的说法,不是专家说的,不要相信.应该有专业的说法. 从他人的网站通过一个接口获取数据,这一直是我感到神奇的事,怎么实现的,一直萦绕于心,想要弄过究竟,怎么是实现的啊! ...

  5. Git学习笔记——一个NB的分布式版本控制系统

    1. 命令: git init           创建新仓库 (在一个空文件下然后执行命令) git clone  + 路径      检出仓库,从本地或从服务器上 git status     查 ...

  6. iOS边练边学--NSURLSessionDataTask实现文件真正的断点续传

    实现重点: NSURLSessionDataTask要设置请求头,从路径中获取文件已经下载的长度(文件没有下载过的话,长度为0).通过这个长度设置请求的Range 如图: 接收到请求的时候key:文件 ...

  7. 【POJ 2104】 K-th Number 主席树模板题

    达神主席树讲解传送门:http://blog.csdn.net/dad3zz/article/details/50638026 2016-02-23:真的是模板题诶,主席树模板水过.今天新校网不好,没 ...

  8. 【Gym 100015A】Another Rock-Paper-Scissors Problem

    题 题意 Sonny出石头剪刀布的猜拳策略是 先出R,然后每连续两段都是打败前一段的出拳, 现在问你第n回合打败他要出什么. 分析 他的策略 R P S PSR  SRP PSRSRPRPS SRPR ...

  9. 【poj1080】 Human Gene Functions

    http://poj.org/problem?id=1080 (题目链接) 题意 给出两个只包含字母ACGT的字符串s1.s2,可以在两个字符串中插入字符“-”,使得s1与s2的相似度最大. Solu ...

  10. sixsix团队“餐站”应用M2阶段发布报告

    一.新功能 客户端 搜索功能 我们在M2中实现了对地点的搜索菜品,可以直接在主页页面中的输入框输入用户喜欢的菜品,系统将返回与对应关键字所对应的选择,更加高效直观的满足客户的口味. 菜品图片加载 我们 ...