0

전체 응용 프로그램이 세로 모드에만 있고 응용 프로그램에서 YouTube 비디오를 재생하고 있습니다. 당신 튜브 들어 UIWebview 사용하고 있습니다. 사용자가 UIWebview에서 재생 버튼을 클릭하면 MPMoviePlayerController가 자동으로 실행됩니다. 그래서 저는 MPMoviePlayerController 객체를 선언하지 않았습니다. 그래서 MPMoviePlayerController가 세로 방향과 가로 방향을 모두 지원하기를 바랍니다. 그러니 제안 해주십시오. 당신이 NavigationController를 사용하는 경우MPMoviePlayerController 방향 설정

+0

이 질문보기 http://stackoverflow.com/questions/25967615/youtube-video-not-playing-in-landscape-mode-in-ios-8 –

답변

3

, 당신은 그것을 서브 클래스 화해, 다음을 수행 할 수 :

#import "MainNavigationController.h" 
#import <MediaPlayer/MediaPlayer.h> 

@implementation MainNavigationController 

-(BOOL)shouldAutorotate 
{ 
    return YES; 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    if ([[[self.viewControllers lastObject] presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]]) 
    { 
     return UIInterfaceOrientationMaskAll; 
    } 
    else 
    { 
     return UIInterfaceOrientationMaskPortrait; 
    } 

} 
@end 

그럼 당신은 모든 방향을 지원하도록 응용 프로그램을 설정해야합니다, 그리고 그것은 당신의 영화를 재생하는 경우에만이 코드는 방향 변경을 허용합니다 'MPMoviePlayerController`.

movie으로 전화 할 때 알림을 보내야하므로 사용자가 portrait이 아닌 다른 방향으로 닫으면 알림은 portrait으로 다시 전환됩니다. 이 같은

뭔가 :

- (IBAction)playButton:(id)sender { 

[[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(moviePlaybackDidFinish) 
               name:MPMoviePlayerPlaybackDidFinishNotification 
               object:self.player.moviePlayer]; 

    NSURL *url = [NSURL URLWithString:videoUrl]; 

    self.player = [[MPMoviePlayerViewController alloc] initWithContentURL:url]; 
    self.player.moviePlayer.movieSourceType = MPMovieSourceTypeFile; 

    [self presentMoviePlayerViewControllerAnimated:self.player]; 
} 

-(void)moviePlaybackDidFinish 
{ 
    [[UIDevice currentDevice] setValue: 
    [NSNumber numberWithInteger: UIInterfaceOrientationPortrait] 
           forKey:@"orientation"]; 
} 

이, 당신을 위해 그것을 내가 어떻게되는지 알려해야합니다.