Created
June 18, 2017 07:57
-
-
Save tkmn0/a2a901251679a2686696cb259ea32935 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//メンバ変数を用意する | |
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