0

我的問題很簡單,教程和答案沒有解決我的問題。

我有設置的應用程序:

enter image description hereMPMoviePlayerViewController在橫向/所有方向

我希望支持我的所有viewControllers只有人像/顛倒方位除了當我想通過播放視頻:

MPMoviePlayerViewController

這是代碼:

MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:[Videos videoURL:video.hash]]; 
if (mp) { 
    isVideoPlaying = YES; 

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

    [self presentMoviePlayerViewControllerAnimated:mp]; 
    mp.moviePlayer.movieSourceType = MPMovieSourceTypeFile; 
    [mp.moviePlayer play]; 
    [mp release]; 
} 

When MPMoviePlayerViewController播放視頻我想支持所有方向。
需要你的幫助。

回答

2

您應該通過以下允許轉速:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations 
} 

IOS 6:

- (NSUInteger)supportedInterfaceOrientations 
{ 

    return UIInterfaceOrientationMaskAll; 
} 

把代碼在調用播放器

+0

不工作,仍然應該是我不能旋轉的所有viewControllers,和VideoViewController一樣,我做電影播放。它只適用於在xcode項目的摘要選項卡中設置所需的方向。爲什麼? –

+0

您的應用程序運行的IOS版本是什麼? –

+0

我成功地使用iOS 5和之前版本。但仍然有問題與ios6 –

0

大家好,我有.m文件同樣的問題我解決了它 -

您需要先更改appdelegate:

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 
{ 
if ([[[NowPlaying sharedManager] playerViewController] allowRotation])//Place your condition here 
{ 
    return UIInterfaceOrientationMaskAll; 
} 
return UIInterfaceOrientationMaskPortrait; 
} 

註冊通知的全屏控制:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillEnterFullscreenNotification:) 
              name:MPMoviePlayerWillEnterFullscreenNotification 
              object:nil]; 

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillExitFullscreenNotification:) 
              name:MPMoviePlayerWillExitFullscreenNotification 
              object:nil]; 

在播放器控制器然後添加一行代碼:

- (void)moviePlayerWillEnterFullscreenNotification:(NSNotification *)notification 
{ 
dispatch_async(dispatch_get_main_queue(),^
       { 
        self.allowRotation = YES; 
       }); 
} 



- (void)moviePlayerWillExitFullscreenNotification:(NSNotification *)notification 
{ 
self.allowRotation = NO; 
[self.moviePlayerController setControlStyle:MPMovieControlStyleNone]; 

dispatch_async(dispatch_get_main_queue(),^
       { 

        //Managing GUI in pause condition 
         if (self.currentContent.contentType == TypeVideo && self.moviePlayerController.playbackState == MPMoviePlaybackStatePaused) 
        { 
         [self.moviePlayerController pause]; 
         if (self.playButton.selected) 
          self.playButton.selected = NO; 
        } 
        self.view.transform = CGAffineTransformMakeRotation(0); 
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait]; 
        self.view.bounds = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height); 
       }); 
} 

這段代碼在iOS6的和iOS7工作正常進行測試。謝謝

相關問題