Question

Before you vote this question down, note, that I've already tried to implement all the solutions available on stackoverflow. Here is the issue:

My application runs only in portrait mode. The only thing which needs to be in landscape is video player. When a user taps on my TableViewCell this block of code is called:

    MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:videoUrl];
    [self presentMoviePlayerViewControllerAnimated:moviePlayer];

After that, I need to give the user the ability to watch video both in portrait and landscape mode. After he is done, everything should get back into portrait mode. I've tried to call this block of code in my AppDelegate.m:

- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    NSUInteger orientations = UIInterfaceOrientationMaskPortrait;

    if ([[self.window.rootViewController presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]]) {
        orientations = UIInterfaceOrientationMaskAllButUpsideDown;
    }

    return orientations;
}

With it everything is fine except one thing - when the video is over or when the user taps "Done" button while in landscape mode, my view controller appears in landscape mode too.

Besides it, I've tried a lot of other methods - but nothing seems to work.

I'll be glad for any help!

Was it helpful?

Solution

Thanks @Shubham - Systematix for the answer.

All that I had to do was to remove every code related to autorotating except this method in AppDelegate:

- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    if ([[window.rootViewController presentedViewController] isKindOfClass:        [MPMoviePlayerViewController class]])
    {
        //NSLog(@"in if part");
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
    else
    {
        //NSLog(@"in else part");
        return UIInterfaceOrientationMaskPortrait;
    }
}

When I did it everything worked like a magic!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top