1、info中支持所有的方向

2、APPDelega.h中添加属性

@property (nonatomic,assign) BOOL allowRotate;

APPdelegate.m中实现方法

//此方法会在设备横竖屏变化的时候调用
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
if (_allowRotate) {
return UIInterfaceOrientationMaskAll;
}else{
return UIInterfaceOrientationMaskPortrait;
}
}

3、在需要旋转的单个页面中添加

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
AppDelegate * delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
delegate.allowRotate = YES;
} - (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
AppDelegate * delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
delegate.allowRotate = NO; if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]){
SEL selector = NSSelectorFromString(@"setOrientation:");
NSInvocation * invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:[UIDevice currentDevice]];
int val = UIInterfaceOrientationPortrait;
[invocation setArgument:&val atIndex:];
[invocation invoke];
}
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
// 屏幕从竖屏变为横屏时执行
NSLog(@"屏幕从竖屏变为横屏"); }else{
// 屏幕从横屏变为竖屏时执行
NSLog(@"屏幕从横屏变为竖屏");
}
} - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
// do something after rotation }

后话

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientChange:) name:UIDeviceOrientationDidChangeNotification object:[UIDevice currentDevice]];
- (void)orientChange:(NSNotification *)notification {
UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
if (orientation == UIDeviceOrientationLandscapeLeft) {
NSLog(@"notification: 屏幕从竖屏变为横屏");
} else if (orientation == UIDeviceOrientationLandscapeRight) {
NSLog(@"notification: 屏幕从竖屏变为横屏");
} else if (orientation == UIDeviceOrientationPortrait) {
NSLog(@"notification: 屏幕从横屏变为竖屏");
}
}

单个APP页面支持屏幕旋转的更多相关文章

  1. app锁定屏幕方向,某一个界面支持屏幕旋转~

    AppDelegate.h 加 @property (nonatomic, assign) BOOL allowRotation; Appdelegate.m加 -(NSUInteger)applic ...

  2. ios 不支持屏幕旋转

    - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; }

  3. iOS 让部分ViewController支持屏幕旋转

    首先,在Xcode里设置整个项目支持的屏幕显示方向: 然后创建一个UINavigationController的子类,然后重载以下属性: 对于需要自定义屏幕方向的ViewController,重载这个 ...

  4. 【Android】[转] Android屏幕旋转使用OrientationEventListener的监听

    说明 遇到一个奇葩的问题,我在使用onConfigChanged拦截屏幕的横竖屏旋转时,发现直接进行180度的横屏/竖屏转换居然没有反应!查找原因发现仅对landscape或者portrait状态有用 ...

  5. iOS实现屏幕旋转

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

  6. iOS学习笔记(3)— 屏幕旋转

    一.屏幕旋转机制: iOS通过加速计判断当前的设备方向和屏幕旋转.当加速计检测到方向变化的时候,屏幕旋转的流程如下: 1.设备旋转时,系统接收到旋转事件. 2.系统将旋转事件通过AppDelegate ...

  7. H5项目常见问题及注意事项,视频全屏,定位,屏幕旋转和触摸,偏页面重构向 来源joacycode的github

    Meta基础知识: H5页面窗口自动调整到设备宽度,并禁止用户缩放页面 //一.HTML页面结构 <meta name="viewport" content="wi ...

  8. iOS 实现单个页面支持横竖屏,其他页面只能竖屏

    最近在自己的项目里面 有需要做一个需求 : app中某一个页面支持横竖屏, 而其他页面只能竖屏. 1 2 实现方法如下: 1 首先需要Xcode中选中支持的屏幕方向  2 Appdelegate中 . ...

  9. View页面内容的旋转,在某些情况下可替代屏幕旋转使用

    这个是在做小秘书的体重曲线图的时候用到的,横排的时候可以多显示些内容,可是由于很多未知的冲突导至屏幕旋转起来非常麻烦,可用用旋转页面的内容来达到旋转屏幕的效果. 代码如下: //旋转90度 CGAff ...

随机推荐

  1. [ Laravel 5.5 文档 ] 官方扩展包 —— 全文搜索解决方案:Laravel Scout

    简介 Laravel Scout 为 Eloquent 模型全文搜索实现提供了简单的.基于驱动的解决方案.通过使用模型观察者,Scout 会自动同步更新模型记录的索引. 目前,Scout 通过 Alg ...

  2. wifidog 源码初分析(2)-转

    上一篇分析了接入设备的首次浏览器访问请求如何通过 防火墙过滤规则 重定向到 wifidog 的 HTTP 服务中,本篇主要分析了 wifidog 在接收到 接入设备的 HTTP 访问请求后,如何将此 ...

  3. 【高德地图SDK】如何实现轨迹平滑移动?

    很多人应该都有类似的经历,叫完车,想看看车离我还有多远距离?但手机屏幕上的车不是一动不动,就是一跳一跳的漂移. 目前市面上大多产品“轨迹平滑移动”做的并不好. 市面上只有快的打车和一号专车实现了平滑移 ...

  4. 通过javac导出Jar包

    我的目录结构d:/test/          ../ src          ../build src下面放java源文件build下面放编译好的classes 下面是我的操作,我在test目录下 ...

  5. python 爬虫 爬取序列博客文章列表

    python中写个爬虫真是太简单了 import urllib.request from pyquery import PyQuery as PQ # 根据URL获取内容并解码为UTF-8 def g ...

  6. 新的Blog

    前两天闲着没事把blog弄了下,之前用jekyll折腾好久都不好使,最后还是决定用Hexo了= =.. .题解在两面都会更新 新Blog地址mlz000.github.io,欢迎来踩>_<

  7. unity3d uv动画

    做个总结吧.算是. 之前做过一个项目,是一个关于太空大战的项目. 算是自己做的吧.大体环境是unity3d + win32,mac上不行.好像不支持这个,原因未知.希望知道的告诉我下. 以下具体说下整 ...

  8. JQuery EasyUI学习笔记

    转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6690888.html  简介与准备 jQuery EasyUI 是一个基于 jQuery 的框架,集成了各种用 ...

  9. cocos2d-js 3.0 RC0 监听返回键、菜单键、进入后台(home键)、恢复显示等事件

    cc.eventManager.addListener({ event: cc.EventListener.KEYBOARD, onKeyReleased: function(keyCode, eve ...

  10. jqPlot图表插件学习之阴阳烛图

    一.准备工作 首先我们需要到官网下载所需的文件: 官网下载(笔者选择的是jquery.jqplot.1.0.8r1250.zip这个版本) 然后读者需要根据自己的情况新建一个项目并且按照如下的方式加载 ...