Skip to content

Instantly share code, notes, and snippets.

@tkmn0
Created June 18, 2017 07:57
Show Gist options
  • Save tkmn0/a2a901251679a2686696cb259ea32935 to your computer and use it in GitHub Desktop.
Save tkmn0/a2a901251679a2686696cb259ea32935 to your computer and use it in GitHub Desktop.
//メンバ変数を用意する
var videoFrame: CGRect? = nil
//向きを伝える
override func viewDidAppear(_ animated: Bool) {
NotificationCenter.default.addObserver(self, selector: #selector(ChatViewController.onOrientationChange(notification:)), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
}
//縦向きに戻った時にまたアスペクト比をを揃える
func onOrientationChange(notification: NSNotification){
let deviceOrientation: UIDeviceOrientation! = UIDevice.current.orientation
if videoFrame != nil {
if UIDeviceOrientationIsPortrait(deviceOrientation){
remoteVideoView.frame = videoFrame!
}
}
}
//videoViewのフレームサイズをメンバ変数へ
func videoView(_ videoView: RTCEAGLVideoView, didChangeVideoSize size: CGSize) {
let width = self.view.frame.width
let height =
self.view.frame.width * size.height / size.width
videoView.frame = CGRect(
x: 0,
y: (self.view.frame.height - height) / 2,
width: width,
height: height)
videoFrame = videoView.frame
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment