1. 屏幕切换时,会发送一个通知。只要注册一个通知:
  1. [[NSNotificationCenter defaultCenter] addObserver:self
  2. selector:@selector(doRotateAction:)
  3. name:UIDeviceOrientationDidChangeNotification
  4. object:nil];

然后在方法里做操作:

  1. -(void) doRotateAction:(NSNotification *) notification{
  2. if ([[UIDevice currentDevice] orientation]==UIInterfaceOrientationPortrait
  3. || [[UIDevice currentDevice] orientation]==UIInterfaceOrientationPortraitUpsideDown) {
  4. NSLog(@">>>portrait");
  5. }else{
  6. NSLog(@">>>landscape");
  7. }
  8. }

如果要在入口文件做切换屏幕,可以判断状态栏的方向:

    1. ////////////////////////////////////
    2. //通知委托状态栏已改变,进横竖屏操作
    3. -(void)application:(UIApplication *)application didChangeStatusBarOrientation:(UIInterfaceOrientation)oldStatusBarOrientation{
    4. //清除背景,防止上一次转屏的图像残留
    5. [imageview setBackgroundColor:[UIColor clearColor]];
    6. //以下是横竖屏4个方向的切换,注意转屏时,无论是转哪个屏。起点坐标都是在portrait方向的起点(0,0)来计算的
    7. if ([[UIDevice currentDevice] orientation]==UIInterfaceOrientationPortrait ) {
    8. NSLog(@">>>portrait"); //home键在下
    9. imageview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 20, 768, 44)];
    10. imageview.backgroundColor = [UIColor redColor];
    11. [_window addSubview:imageview];
    12. }else if([[UIDevice currentDevice] orientation]==UIInterfaceOrientationPortraitUpsideDown){
    13. NSLog(@">>>PortraitUpsideDown"); //home键在上
    14. imageview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 960, 768, 44)];
    15. imageview.backgroundColor = [UIColor redColor];
    16. [_window addSubview:imageview];
    17. }else if([[UIDevice currentDevice] orientation]==UIInterfaceOrientationLandscapeLeft){
    18. NSLog(@">>>LandscapeLeft"); //home键在左
    19. imageview = [[UIImageView alloc] initWithFrame:CGRectMake(20, 0, 44, 1024)];
    20. imageview.backgroundColor = [UIColor redColor];
    21. [_window addSubview:imageview];
    22. }
    23. else if([[UIDevice currentDevice] orientation]==UIInterfaceOrientationLandscapeRight){
    24. NSLog(@">>>LandscapeRight"); //home键在右
    25. imageview = [[UIImageView alloc] initWithFrame:CGRectMake(704, 0, 44, 1024)];
    26. imageview.backgroundColor = [UIColor redColor];
    27. [_window addSubview:imageview];
    28. }
    29. }

ios 横竖屏通知的更多相关文章

  1. iOS 横竖屏切换(应对特殊需求)

    iOS 中横竖屏切换的功能,在开发iOS app中总能遇到.以前看过几次,感觉简单,但是没有敲过代码实现,最近又碰到了,demo尝试了几种情况,这里就做下总结.注意 横屏两种情况是反的你知道吗? UI ...

  2. iOS 横竖屏切换解决方案

    iOS要实现横竖屏切换很简单,不需要使用任何第三方,只需要实现几个方法就可以了. 1.设置系统支持横竖屏[General]->[Targets]-> [Deployment info]-& ...

  3. iOS 横竖屏适配

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

  4. IOS横竖屏控制与事件处理

    公司App里面有个需求,即所有界面都是竖屏,且不允许横屏切换,唯独有一个图表界面允许横屏.那么,根据此需求处理如下: 首先,确保App本身应该允许转屏切换: 再次,我的App里面都是走UINaviga ...

  5. iOS横竖屏切换的一些坑(持续更新)

    最近在做视频类的App,遇到视频滚动播放的坑,紧接着就是横竖屏问题.之前太过天真不想做横竖屏配置.只是想旋转视频View,但是分享什么的包括AlertView还是竖屏样式,项目着急上线(1周提交一次也 ...

  6. iOS横竖屏

    现在开发的APP大部分界面是竖屏的,只有视频播放的界面和webview阅读文字的界面是可以横屏操作的. 那么就进行如下处理: 1.首先确保APP支持横屏旋转 2.我的App里面都是走UINavigat ...

  7. iOS 横竖屏适配 笔记

    研究消息转发机制 已经一周多了,但是 还是没整理出博客, 还是先写一个 项目中遇到的 横竖屏适配问题. // 开启自动转屏 - (BOOL)shouldAutorotate { return YES; ...

  8. 代码处理 iOS 的横竖屏旋转

    一.监听屏幕旋转方向 在处理iOS横竖屏时,经常会和UIDeviceOrientation.UIInterfaceOrientation和UIInterfaceOrientationMask这三个枚举 ...

  9. [iOS]终极横竖屏切换解决方案

    [iOS]终极横竖屏切换解决方案 大家的项目都是只支持竖屏的吧?大多数朋友(这其中当然也包括博主),都没有做过横屏开发,这次项目刚好有这个需求,因此把横竖屏相关的心得写成一遍文章供诸位参考. 01.综 ...

随机推荐

  1. 在PHP中遍历数据库表中的数据

    数据库中的数据: //1.分别将每一行的每一列遍历出来 //mysql_fetch_row()函数在每一次遍历后会将指针向后自动移动一个单位 while($row=mysql_fetch_row($r ...

  2. git之create local reposition(创建本地仓库)

    1.创建名为git-reposition的仓库 mkdir home/sunjf/git-reposition 注:home/sunjf可以指定为你想要的路径下面 2.初始化仓库 cd ~/git-r ...

  3. ProgressDialog的使用

    ProgressDialog 继承自AlertDialog,AlertDialog继承自Dialog,实现DialogInterface接口. ProgressDialog的创建方式有两种,一种是ne ...

  4. iOS开发——UI进阶篇(十)导航控制器、微博详情页、控制器的View的生命周期

    一.导航控制器出栈 1.initWithRootViewController本质 UIViewController *vc = [[OneViewController alloc] init]; // ...

  5. [codeforces 339]C. Xenia and Weights

    [codeforces 339]C. Xenia and Weights 试题描述 Xenia has a set of weights and pan scales. Each weight has ...

  6. 符瑞艺 160809228_C语言程序设计实验2 选择结构程序设计

    实验2- 输入3个数,并按由大到小的顺序输出. 实验要求: 编写一个C程序,输入3个数,并按由大到小的顺序输出. 参考: 源码: #include <stdio.h> int main() ...

  7. Unable to add window -- token null is not for an application

    导致报这个错是在于new AlertDialog.Builder(mcontext),虽然这里的参数是AlertDialog.Builder(Context context)但我们不能使用getApp ...

  8. springboot 连接池wait_timeout超时设置

    使用springboot 线程池连接MySQL时,mysql数据库wait_timeout 为8个小时,所以程序第二天发现报错,在url配置了 autoReconnect=true 也不行,查询配置以 ...

  9. linux创建子进程--fork()方法

    (1)fork()的定义 fork()函数是Unix中派生新进程的唯一方法,声明如下: #include <unistd.h> pid_t fork(void); 我们需要理解的是,调用一 ...

  10. Java程序优化的一些最佳实践(转)

    衡量程序的标准 衡量一个程序是否优质,可以从多个角度进行分析.其中,最常见的衡量标准是程序的时间复杂度.空间复杂度,以及代码的可读性.可扩展性.针对程序的时间复杂度和空间复杂度,想要优化程序代码,需要 ...