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. 【应用】R--判断类别型属性之间是否有相关性(相互之间是否独立)

    检验某学区所有在售房源中,小区与楼栋类别(低层:多层;小高层:高层)是否相关 导入数据: > house<- read.table("house_data.txt", ...

  2. PHP跨页面传递时session失效

    一直都是使用wamp作为本地的PHP集成开发环境 今天遇到一个很奇怪的问题,就是在跨页面传递时session竟然失效了,而之前从来没有出现过这种问题 因为使用的是开源的php框架为了测试方便就新建了两 ...

  3. Sublime 格式化代码 设置快捷键以及插件使用

    实在sublime中已经自建了格式化按钮: Edit  ->  Line  ->  Reindent 只是sublime并没有给他赋予快捷键,所以只需加上快捷键即可 Preference ...

  4. maven 配置篇 之pom.xml

    http://www.blogjava.net/zyl/archive/2006/12/30/91055.html http://maven.apache.org/pom.html的翻译.     m ...

  5. C++代码复习笔记:第三章

    getline这个方法的使用, 可以获取用户输入的一行数据, 保存到数组中: #include <iostream> #include <string> int main() ...

  6. UiTextField 限制输入长度

    -(BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementS ...

  7. javascript中this的妙用

    this是javascript语言的一个关键字,它代表函数运行时,自动生成的一个内部对象,只能在函数内部使用. this总是指向对象,并且为调用函数的那个对象: //调用普通函数 function f ...

  8. Zabbix-Agent在主动模式启动服务后,提示no active checks on server [139.219.xx.xx:10051]: host [139.219.xx.xx] not found

    一.解决方法

  9. POSTGRESQL 查看数据库 数据表大小

    1.查看数据库大小: select pg_database_size('log_analysis'); select pg_database_size('log_analysis'); pg_data ...

  10. 算法笔记_202:第三届蓝桥杯软件类决赛真题(Java高职)

    目录 1 填算式 2 提取子串 3 机器人行走 4 地址格式转换 5 排日程   前言:以下代码仅供参考,若有错误欢迎指正哦~ 1 填算式 [结果填空] (满分11分) 看这个算式: ☆☆☆ + ☆☆ ...