ios代码控制屏幕旋转

1
2
//参数1 为 旋转方向, 参数2未固定方向属性 会手动出发旋转事件
UIDevice.currentDevice().setValue(UIDeviceOrientation.Portrait.rawValue, forKey: "orientation")

2 屏幕旋转的侦听

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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;
}
}
}
Author

陈昭

Posted on

2016-09-18

Updated on

2021-12-27

Licensed under

You need to set install_url to use ShareThis. Please set it in _config.yml.
You forgot to set the business or currency_code for Paypal. Please set it in _config.yml.

Kommentare

You forgot to set the shortname for Disqus. Please set it in _config.yml.