chenzhao

  • java
  • iOS
  • IT
知识积累
不积跬步无以至千里
  1. 首页
  2. iOS
  3. 正文

ios代码控制屏幕旋转

2016年 9月 18日 88点热度 0人点赞 0条评论
//参数1 为 旋转方向, 参数2未固定方向属性 会手动出发旋转事件
UIDevice.currentDevice().setValue(UIDeviceOrientation.Portrait.rawValue, forKey: "orientation")

2 屏幕旋转的侦听

NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.viewchange(_:)), name: UIApplicationDidChangeStatusBarOrientationNotification, object: nil)


    /**
    界面变化处理函数
    
    - parameter sender: AnyObject
    */
    func viewchange(sender:AnyObject){
        
        let orientation = UIApplication.sharedApplication().statusBarOrientation

            switch orientation{
            case UIInterfaceOrientation.LandscapeRight ,UIInterfaceOrientation.LandscapeLeft:
                var video_W = stageWidth
                var video_H = stageHeight
                // 不同系统版本宽高取出有区别
                if #available(iOS 8.0, *){
                    video_W = stageWidth
                    video_H = stageHeight
                }else{
                    video_W = stageHeight
                    video_H = stageWidth
                }
                self.videoView.setVideoFrame(CGRect(x: 0, y: 0, width: video_W, height: video_H))
                
            case UIInterfaceOrientation.Portrait:
                
               // playerlayer.frame = PortraitFrame
                self.videoView.setVideoFrame(PortraitFrame)
                
            default:
                break;
                
            }
        }
      
        
    }
标签: 暂无
最后更新:2022年 11月 11日

陈昭

IT 程序员

打赏 点赞
< 上一篇
下一篇 >

文章评论

取消回复

COPYRIGHT © 2022 chenzhao. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang