//参数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;
}
}
}
文章评论