http://lizhuang.iteye.com/blog/1684881

在iPad应用开发时如何让设备只支持横屏(landscape)模式,我做了多次尝试,并没有发现比较简捷的设置方法。我尝试了大概大概3种方式。 
1、通过XCode设置“iPad Deployment info”,只选择横屏左和横屏右,部署测试后并没有生效,这种方法实质是在xxx_info.plist项目配置文件中添加如下信息: 
<key>UISupportedInterfaceOrientations~ipad</key> 
<array> 
<string>UIInterfaceOrientationLandscapeLeft</string> 
<string>UIInterfaceOrientationLandscapeRight</string> 
</array> 
2、通过对每个nib文件在IB中设置orientation为landscape,此法也不生效。 
3、重载shouldAutorotateToInterfaceOrientation:方法,这种方式是可行的。具体如下: 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 

    // Return YES for supported orientations 
return ((interfaceOrientation ==UIDeviceOrientationLandscapeLeft)||(interfaceOrientation ==UIDeviceOrientationLandscapeRight)); 

如果第一种方式生效,那么比较完美。虽然第三种方式可以完全满足横屏的需求,但是实现起来比较stupid,需要在每个controller中都重载shouldAutorotateToInterfaceOrientation:方法,当然也可以通过扩展UIViewController的方式来避免重复劳动。但是感觉也有点不太直接,期待有人指出sdk本身是否就有简捷方式支持。

iPad的界面布局好多时候都要做两套------横屏和竖屏,但在界面切换时,该让哪个布局显示就要判断了,有多种方法,我记录下我用的一种,感觉比较方便: 
          NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; //Get the notification centre for the app 
    [nc addObserver:self //Add yourself as an observer 
           selector:@selector(orientationChanged) 
               name:UIDeviceOrientationDidChangeNotification 
             object:nil];//这个函数用来获取当前设备的方向, 
- (void)orientationChanged 

    //UIView *ftView = [self.view viewWithTag:200]; 
    if([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft || [[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)//判断左右 
    { 
         //界面的新布局 
    } 
    if([[UIDevice currentDevice] orientation] == UIInterfaceOrientationPortrait )//我有个方向不支持,如果想都支持那就不要这个if条件就行了 
    { 
         //界面的新布局 
    } 
}

iOS 5 上真机测试过了。很方便,用过后才能体会到,这里不多说了!

IOS 使用横屏的更多相关文章

  1. iOS的横屏(Landscape)与竖屏(Portrait)InterfaceOrientation

    http://www.molotang.com/articles/1530.html 接着上篇写的触摸事件,这次借机会整理下iOS横屏和竖屏的翻转方向支持,即InterfaceOrientation相 ...

  2. iOS强制横屏

    由于项目需求,需要整个项目页面都是竖屏,唯独一个折线图页面强制性横屏显示. 网上逛了许多帖子,也看了好多大神的提供的方法,都没能够实现本屌丝想要的效果.没办法自己研究自己搞,借鉴各路大神的思路,最后费 ...

  3. cocos2d-x ios 设置横屏/竖屏(全)

    Cocos2d-x项目\iOS\RootViewController.mm文件中. 以下方法任选其一即可…      本人机子函数二ok! 函数一: (BOOL)shouldAutorotateToI ...

  4. iOS强制横屏或强制竖屏

    原文链接 https://www.jianshu.com/p/d6cb54d2eaa1 亲测第二种我这边是阔以滴 第一种解决方案(不推荐,直接跳过看第二种解决方案): //强制转屏 - (void)i ...

  5. iOS 强制横屏

    // // AAAAViewController.m // hengp // // Created by 朱信磊 on 15/2/13. // Copyright (c) 2015年 niit. Al ...

  6. iOS 视频播放横屏,隐藏状态栏

    MPMoviePlayerViewController *moviePlayerViewController = [[MPMoviePlayerViewController alloc] init]; ...

  7. IOS开发基础

    http://blog.csdn.net/wokenshin/article/details/50292253 1.修改UI大小 2.设置颜色 3.禁止横屏 4.点击空白处隐藏键盘 5.弹出键盘时,后 ...

  8. ios和android适配问题总结

    _________________________________________________________________________________ 相关知识点 移动端. 适配(兼容). ...

  9. iOS拍照图片旋转的问题

    很久之前,遇到了这种情况,iOS某端拍照上传到服务器,其他iOS端从服务器下载该照片展示,发现图片逆时针旋转了90度.当时百度了一下,找到一段代码修正image方向,问题解决了,但没有深入理解底层原理 ...

随机推荐

  1. Bootstrap系列 -- 18. 表单控件大小

    前面看到的表单控件都正常的大小.可以通过设置控件的height,line-height,padding和font-size等属性来实现控件的高度设置.不过Bootstrap框架还提供了两个不同的类名, ...

  2. [AHOI2013]找硬币(搜索)

    [Ahoi2013]找硬币 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 348  Solved: 114[Submit][Status] Descri ...

  3. EasyUI之Form load函数IE8下设置Radio或Checkbox的BUG

    EasyUI的form的load函数很好用,表单赋值就靠它了,简单方便.我们可以指定url以Ajax加载,如: 1: $('#ff').form('load', 'ajax/common') JSON ...

  4. RestFul API初识

    python Restful API 微博开放平台: open.weibo.com: 点击文档进入API查看界面 点击API文档进行查看: 比如点开粉丝数的API可以看到: pro.jsonlint. ...

  5. Spring security 学习 (自助者,天助之!)

    自己努力,何必要强颜欢笑的求助别人呢?  手心向下不求人! Spring security学习有进展哦: 哈哈! 1.页面都是动态生产的吧! 2.设置权限:  a:pom.xml配置jar包 b:cr ...

  6. attempted to assign id from null one-to-one

    one-to-one在hibernate中可以用来作为两张表之间的主键关联,这也是hibernate中主键关联的一种用法,这样在一张表中的ID,在生成另外一张表的同时回自动插入到相应的ID字段中去,相 ...

  7. hdu1711 KMP

    #include<stdio.h> #include<string.h> #define maxn 1000010 int next[maxn],s[maxn],p[maxn] ...

  8. 【CodeForces 599A】D - 特别水的题4- Patrick and Shopping

    Description  meter long road between his house and the first shop and a d2 meter long road between h ...

  9. Day1 三级目录

    d_city = { "河南" : {"郑州" : ["二七区","中原区","回族管城区",&qu ...

  10. TortoiseSVN客户端如何更改新的URL

    问题: 我们的服务器换了新的URL地址,这时候我们本地的SVN访问帐号和地址就要重新定义了. 解决步骤: 1:重新定义SVN的URL,右键(TortoiseSVN) → Relocate → 输入你新 ...