Bellow I have some code that i have placed in my AppDelegate.h & .m. This code detects when my MPMoviePlayerController(s) have entering full-screen and exited full-screen through notifications. Once the notifications are called it sets allowRotation
to equal yes and this then allows the user to rotate the view. However once the user has excited full-screen and is still in a certain oreinentation the player dismisses but leaves view in the orieintation that it was place in by the user whilst watching the video. This is due to the exit-full-screen notification being called but the -(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
not being called. So it only re-rotates to port rate when the user rotates the device. But I do not want this and want it to rotate as soon as the notification is called. can anybody help?
Here is my code:
.h
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (nonatomic) BOOL allowRotation;
@end
.m @synthesize allowRotation;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillEnterFullscreenNotification:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(MPMoviePlayerDidExitFullscreen:) name:MPMoviePlayerDidExitFullscreenNotification object:nil];
allowRotation = NO;
return YES;
}
- (void) MPMoviePlayerDidExitFullscreen:(NSNotification*)notification {
NSLog(@"calling1");
self.allowRotation = NO;
}
- (void) moviePlayerWillEnterFullscreenNotification:(NSNotification*)notification {
NSLog(@"calling");
self.allowRotation = YES;
}
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if (self.allowRotation == YES) {
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
else if (self.allowRotation == NO){
NSLog(@"portrait");
return UIInterfaceOrientationMaskPortrait;
}
}
The interface rotation calls are called when the UI layout is done at the start and changing that dynamically at a later point is not going to change the orientation.