Skip to content

Instantly share code, notes, and snippets.

@paztek
Last active June 11, 2019 20:54
Show Gist options
  • Save paztek/9770476 to your computer and use it in GitHub Desktop.
Save paztek/9770476 to your computer and use it in GitHub Desktop.
Allows videos to rotate in landscape when displayed in a portrait only iOS app
#import "AppDelegate.h"
#import <MediaPlayer/MediaPlayer.h>
@implementation AppDelegate
{
BOOL _isFullScreen;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// We register ourselves to be notified when the movie player enters or exits full screen
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(willEnterFullScreen:)
name:MPMoviePlayerWillEnterFullscreenNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(willExitFullScreen:)
name:MPMoviePlayerWillExitFullscreenNotification
object:nil];
return YES;
}
#pragma mark - Allowing the movie players to rotate in fullscreen
- (void)willEnterFullScreen:(NSNotification *)notification
{
_isFullScreen = YES;
}
- (void)willExitFullScreen:(NSNotification *)notification
{
_isFullScreen = NO;
}
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if (_isFullScreen) {
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
} else {
return UIInterfaceOrientationMaskPortrait;
}
}
@ShivamKJJW
Copy link

ShivamKJJW commented Oct 12, 2017

@Serlight In iOS 10.0 onwards I will prefer to use AVPlayerViewController from AVKit. It has the auto rotate support inbuilt even if you have the app locked in portrait mode. I know I am very late to reply but it might be helpful for other developers.

@ferrerod
Copy link

ferrerod commented May 3, 2018

@ShivamKJJW, good call. No need to add landscape support to a portrait only app just for AVPlayerViewController.

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