Reverting to portrait after Done pressed on movie player?

前端 未结 4 940
孤街浪徒
孤街浪徒 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

提交回复
热议问题