Last active
June 11, 2019 20:54
-
-
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
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 "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, 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
@Serlight In iOS 10.0 onwards I will prefer to use
AVPlayerViewController
fromAVKit
. 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.