在ios6之前我们旋转屏幕只需要实现shouldAutorotateToInterfaceOrientation就行了

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
但是ios6上这个就失效了,需要实现shouldAutorotate 和 supportedInterfaceOrientations
具体步骤是

1. Delegate里面要分开判断ios版本,setRootViewController方法是不同的:
 if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0){
// warning: addSubView doesn't work on iOS6
[self.window addSubview: navController.view];
}
else{
// use this mehod on ios6
[self.window setRootViewController:navController];
}
2. 因为我们要向下兼容, 所以shouldAutorotateToInterfaceOrientation必须保留, 再添加shouldAutorotate 和 supportedInterfaceOrientations
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
这样应该没问题了, 但是需要注意的有两点:
1. 必须在.plist文件中添加你需要旋转的方向,要对应, 不然还是没效果
2. 我这里的rootView是UINavigationController, 所以要子类化并添加上面的两个方法, 但是我是添加了Category来实现的
UINavigationController + Rotation.h
@interface UINavigationController (Rotation)
@end
UINavigationController + Rotation.m
@implementation UINavigationController (Rotation)
- (BOOL)shouldAutorotate {
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}
@end

ios 屏幕旋转的问题的更多相关文章

  1. iOS屏幕旋转 浅析

    一.两种orientation 了解屏幕旋转首先需要区分两种orientation 1.device orientation 设备的物理方向,由类型UIDeviceOrientation表示,当前设备 ...

  2. 【转】IOS屏幕旋转与View的transform属性之间的关系,比较底层

    iTouch,iPhone,iPad设置都是支持旋转的,如果我们的程序能够根据不同的方向做出不同的布局,体验会更好. 如何设置程序支持旋转呢,通常我们会在程序的info.plist中进行设置Suppo ...

  3. IOS屏幕旋转思路和实践

    这段时间同事在做一个直播项目,项目有个需求:一个界面需要手动设置屏幕的方向,设置好之后方向不能变化.完成这个需求花了特别大的精力,归因是网上关于屏幕旋转的知识比较凌乱,解决问题花费不少时间,最后决定把 ...

  4. iOS 屏幕旋转 nav+tabbar+present(网页) 2016

    如题,最近一个app架构为 nav + tabbar ,需求是 在点击tabbar中的一个菜单项时,弹出网页,该网页需要横屏显示,其他页面不变  都保持竖屏. XCode Version 7.2.1 ...

  5. iOS屏幕旋转

    三种方法 需求:全局主要是竖屏 个别界面需要横屏

  6. 【转】IOS设备旋转的内部处理流程以及一些【优化建议】

    加速计是整个IOS屏幕旋转的基础,依赖加速计,设备才可以判断出当前的设备方向,IOS系统共定义了以下七种设备方向: typedef NS_ENUM(NSInteger, UIDeviceOrienta ...

  7. iOS实现屏幕旋转

    iOS实现屏幕旋转有两种方式 1. 应用本身支持 2. 手动旋转UIView (这种方式我没找到旋转 系统控件的方法 如:键盘.导航.UIAlertView) 如果你只是要把竖屏的播放器,做成支持横屏 ...

  8. ios实现屏幕旋转的方法

    1.屏蔽AppDelegate下面的屏幕旋转方法 #pragma mark - 屏幕旋转的 //- (UIInterfaceOrientationMask)application:(UIApplica ...

  9. 监听iOS检测屏幕旋转状态,不需开启屏幕旋转-b

    -(void)rotation_icon:(float)n { UIButton *history_btn= [self.view viewWithTag:<#(NSInteger)#>] ...

随机推荐

  1. Arrays.sort和Collections.sort实现原理解析

    Arrays.sort和Collections.sort实现原理解析 1.使用 排序 2.原理 事实上Collections.sort方法底层就是调用的array.sort方法,而且不论是Collec ...

  2. Springboot 之 Hibernate自动建表(Mysql)

    Springboot 之 Hibernate自动建表(Mysql) 2016年10月21日 10:39:44 阅读数:8180 本文章来自[知识林] 引入Maven依赖包 <dependency ...

  3. r语言 技巧总结

    1.table函数返回众数,再转为dataframe as.data.frame(table(x)) 2.使用which 返回数组下标 which(rs.list=="rs1008507&q ...

  4. python 两个字典合并

    dict1={1:[1,11,111],2:[2,22,222]}dict2={3:[3,33,333],4:[4,44,444]}合并两个字典得到类似 {1:[1,11,111],2:[2,22,2 ...

  5. openfire 详细介绍一

    XMPP ExtensibleMessaging and Presence Protocol,简单的来讲,它就是一个发送接收处理消息的协议,但是这个协议发送的消息,既不是二进制的东东也不是字符串,而是 ...

  6. am335x i2c分析

    /***************************************************************************** * am335x i2c分析 * i2c驱 ...

  7. (转)SDL 1.2 to 2.0 Migration Guide--SDL1.2更新到SDL2.0指南

    SDL 1.2 to 2.0 Migration Guide 目录 SDL 1.2 to 2.0 Migration Guide Translations Introduction Overview ...

  8. Perl Spreadsheet::WriteExcel 模块自动生成excel 文件

    Spreadsheet::WriteExcel 是一个跨平台的生成excel文件的模块, 可以方便的设置单元格内容, 样式, sheet 的名称: 但是默认情况下中文会乱码, 需要用Encode模块进 ...

  9. 【Java集合的详细研究5】Java中Array与ArrayList的主要区别

    1)精辟阐述:可以将 ArrayList想象成一种“会自动扩增容量的Array”. 2)Array([]):最高效:但是其容量固定且无法动态改变:     ArrayList:  容量可动态增长:但牺 ...

  10. js事件总结

    事件冒泡: 什么是事件冒泡,就是最深dom节点触发事件,然后逐级向最外层触发事件.打个比方一棵dom tree:li<ul<div每级都有事件绑定,然后我们触发li的事件,这时ul上的事件 ...