coding_cover676x469
So it’s not Tuesday but we’ve been really busy doing exciting stuff, so we apologize that it’s a day late. But get ready to forgive us because in this tutorial we will learn how EASY it is to allow for the rotation of videos to landscape mode when displayed in a portrait-only iOS app.

After spending numerous hours looking for how to display video in landscape when played full-screen on an portrait-only iOS app I finally found a solution that is so easy it hurts! OUCH! See?
The only code you need to add is in your appDelegate! :)

class AppDelegate: UIResponder, UIApplicationDelegate {
 
    var window: UIWindow?
 
    var _isFullScreen:Bool = false // ADD VARIABLE THE WILL LET THE APP DELEGATE KNOW WHEN WE ARE ALLOWING LANDSCAPE
 
    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        /* YOU CODE */
        NSNotificationCenter.defaultCenter().addObserver(
            self,
            selector: "willExitFullScreen:",
            name: MPMoviePlayerWillExitFullscreenNotification,
            object: nil)
 
 
        NSNotificationCenter.defaultCenter().addObserver(
            self,
            selector: "willEnterFullScreen:",
            name: MPMoviePlayerWillEnterFullscreenNotification,
            object: nil)
 
       return true
    }
 
    func willExitFullScreen(notification: NSNotification){
        debugPrintln("willExitFullScreen")
        _isFullScreen = false
    }
 
    func willEnterFullScreen(notification: NSNotification){
        debugPrintln("willEnterFullScreen")
        _isFullScreen = true
    }
 
    func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> Int {
        if (_isFullScreen) {
            return Int(UIInterfaceOrientationMask.Portrait.rawValue) | Int(UIInterfaceOrientationMask.LandscapeLeft.rawValue) | Int(UIInterfaceOrientationMask.LandscapeRight.rawValue)
        } else {
            return Int(UIInterfaceOrientationMask.Portrait.rawValue)
        }
    }

You are done!!