Skip to content

Instantly share code, notes, and snippets.

@MylesCaley
Last active February 1, 2019 03:56
Show Gist options
  • Save MylesCaley/75a08a3006ad0109271b5fdc5075dfc7 to your computer and use it in GitHub Desktop.
Save MylesCaley/75a08a3006ad0109271b5fdc5075dfc7 to your computer and use it in GitHub Desktop.
When you have a portrait-only app you may still want to allow rotation when the app plays full screen media. This is a decent solution by creating a notification to signal a "full screen". Only tested on iOS9.
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var isFullScreen = false
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// create notifications from wherever to signal fullscreen
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.willEnterFullScreen(_:)), name: "MediaEnterFullScreen", object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.willExitFullScreen(_:)), name: "MediaExitFullScreen", object: nil)
return true
}
func willEnterFullScreen (notification: NSNotification) {
isFullScreen = true
}
func willExitFullScreen (notification: NSNotification) {
isFullScreen = false
}
func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask {
return isFullScreen == true ? UIInterfaceOrientationMask.All : UIInterfaceOrientationMask.Portrait
}
}
@ingconti
Copy link

note anyway those calls are deprecated since ios9 and as per Apple ADC docs, notifications are 👍

MPMoviePlayerWillEnterFullscreen
and so on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment