Last active
February 1, 2019 03:56
-
-
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.
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
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 | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
note anyway those calls are deprecated since ios9 and as per Apple ADC docs, notifications are 👍
MPMoviePlayerWillEnterFullscreen
and so on.