Reverting to portrait after Done pressed on movie player?

前端 未结 4 939
孤街浪徒
孤街浪徒 2020-12-20 09:09

I\'ve got a MPMoviePlayer working. It is designed to show a postage-stamp size movie as a subview in the view. When the phone is rotated into landscape, it goes into full sc

相关标签:
4条回答
  • 2020-12-20 09:25
    [[NSNotificationCenter defaultCenter] addObserver:self
                                      selector:@selector(_moviePlayerWillExitFullscreen:)
                                             name:MPMoviePlayerWillExitFullscreenNotification object:nil];
    
    
    - (void)_moviePlayerWillExitFullscreen:(NSNotification *)notification 
    {
        CGFloat ios = [[[UIDevice currentDevice] systemVersion] floatValue];
        CGFloat min = 5.0;
        if (ios >= min)
        {
            if (self.interfaceOrientation != UIInterfaceOrientationPortrait)
            {  
                if([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortrait])
                {
                    [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
                    [self willRotateToInterfaceOrientation:self.interfaceOrientation duration:0];
                    [UIViewController attemptRotationToDeviceOrientation];
                } 
            }
        }   
    }
    

    Note that this only works in ios 5.0 and later, and you will get a warning that setOrientation is not supported, but it works pretty well

    0 讨论(0)
  • 2020-12-20 09:29

    I was the same problem and now I am telling you how I solved it. I don't know the below method is right or wrong but it work fine.

    • Instead of opening MPMoviePlayer in view open it in a new viewController. I mean create a new UIViewController to show the movie and push it some how so that user will not understood that they are redirecting into a new screen.
    • Disable the parent screen for landscape mode and allow MovieViewController to landscape.
    • When user press the done button or close button simply pop the viewController and as the previous screen don't support landscape mode so the screen will automatically shows in portrait mode.
    0 讨论(0)
  • 2020-12-20 09:34

    @cannyboy...you just need to use below method in your APPDelegate.m if your application only works with portrait mode

    - (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;
    }}
    
    0 讨论(0)
  • 2020-12-20 09:46

    One way you could try is to force your device to think it is in portrait mode. To do this, try using:

    [[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait];
    

    If you do not want your device to show landscape while not playing a movie, you will also have to add some logic to your code that you have shown above to only change to landscape if the movie is playing.

    0 讨论(0)
提交回复
热议问题