美文网首页
ios屏幕旋转

ios屏幕旋转

作者: AntKing | 来源:发表于2017-05-09 21:35 被阅读0次

在View中监听屏幕的旋转

  • 第一种方法,我们在view的生命周期的layoutSubviews方法中监听statusBarOrientation,达到监听屏幕的横竖屏状态
- (void)layoutSubviews

{

     [self _shouldRotateToOrientation:(UIDeviceOrientation)[UIApplication sharedApplication].statusBarOrientation];//这里推荐使用状态栏判断

}

-(void)_shouldRotateToOrientation:(UIDeviceOrientation)orientation {
   if (orientation == UIDeviceOrientationPortrait ||orientation ==
                UIDeviceOrientationPortraitUpsideDown) { // 竖屏

    } else { // 横屏

    }
}
  • 第二种方法,使用通知监听屏幕的横竖屏状态
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientChange:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];

- (void)orientChange:(NSNotification *)notification{
UIInterfaceOrientation interfaceOritation = [[UIApplication sharedApplication] statusBarOrientation];

/*
statusBarOrientation   4种状态:
UIInterfaceOrientationUnknown            = UIDeviceOrientationUnknown,
UIInterfaceOrientationPortrait           = UIDeviceOrientationPortrait,
UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
UIInterfaceOrientationLandscapeLeft      = UIDeviceOrientationLandscapeRight,
UIInterfaceOrientationLandscapeRight     = UIDeviceOrientationLandscapeLeft

*/
}

  • 第三种在控制器中如果想手动控制屏幕的旋转,如视频播放的横竖屏旋转,我们可以用以下方法来实现,使用这种方法要把
    这里的控制横竖屏的勾都取消掉
Snip20170916_4.png
class AppDelegate: UIApplicationDelegate{

//添加一个控制屏幕旋转的属性
var allowRotation : Bool = false

    ///横竖屏解决方案
    func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
        if allowRotation == true {
            return .all
        }else{
            return .portrait
        }
    }
}


//在其他要旋转的控制器中只需要设置allowRotation的值就可以了

        // 用appdelegate来控制设备的旋转
        let appdelegate = UIApplication.shared.delegate as! AppDelegate
        appdelegate.allowRotation = true


    // MARK:-----屏幕旋转---------------
    override var shouldAutorotate: Bool {
        return true
    }

    override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
        if player.isLocked {
            return .landscape
        } else {
            return .all
        }
    }



相关文章

  • 屏幕旋转

    屏幕旋转 推荐文档 了解UIWindow——UIWindow实践 iOS屏幕旋转问题总结 IOS:屏幕旋转与变换 ...

  • OC - 屏幕旋转(自动旋转、手动旋转、兼容iOS6之前系统)

    导读: 一、iOS6之前屏幕旋转知识了解 二、iOS6(包括iOS6)之后屏幕旋转知识了解 三、自动旋转具体操作 ...

  • 屏幕旋转和弹出框

    iOS中控制屏幕旋转相关方法 shouldAutorotate:是否支持屏幕旋转 alertView:clicke...

  • iOS Rotation

    iOS屏幕旋转学习笔记iOS开发中使用屏幕旋转功能的相关方法 1、基本知识点解读 了解屏幕旋转首先需要区分两种 o...

  • iOS传感器:实现一个随屏幕旋转的图片

    iOS传感器:实现一个随屏幕旋转的图片 iOS传感器:实现一个随屏幕旋转的图片

  • iOS 屏幕旋转处理

    iOS 屏幕旋转处理 在 iOS 设备上, 屏幕旋转是个挺坑比的问题. 苹果希望 app 对整个 app 做统一的...

  • iOS屏幕旋转

    方式一 假旋转 修改view的transform,通过旋转来实现横屏 工程配置 重写shouldAutorotat...

  • iOS 屏幕旋转

    第一种 在基类控制器,RootTableViewController,RootNaviViewController...

  • iOS屏幕旋转

    一、两种方向的区别 设备方向设备的物理方向,由类型UIDeviceOrientation表示,当前设备方向获取方式...

  • iOS屏幕旋转

    iOS屏幕旋转 1.基本属性和概念 shouldAutorotate supportedInterfaceOrie...

网友评论

      本文标题:ios屏幕旋转

      本文链接:https://www.haomeiwen.com/subject/qqbitxtx.html