Created
November 8, 2016 09:30
-
-
Save bleft/0b9716e35a0b936382a55e15c300c757 to your computer and use it in GitHub Desktop.
recognizes when a AVPlayerController changes to full screen or back. There you can handle auto rotation behavior or other smart things
This file contains 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
// add your view as observer | |
func addVideoBoundsObserver(){ | |
playerController?.contentOverlayView?.addObserver(self, forKeyPath: "bounds", options: .new, context: nil) | |
} | |
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { | |
if keyPath == "bounds" { | |
guard let new = change?[NSKeyValueChangeKey.newKey] as? CGRect | |
else { return } | |
if new.size == UIScreen.main.bounds.size { | |
print("Player in full screen") | |
} else { | |
print("Player not in full screen") | |
} | |
} | |
} | |
// dont forgett to remove the observer! | |
deinit { | |
playerController?.contentOverlayView?.removeObserver(self, forKeyPath: "bounds") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment