0

我的问题很简单,教程和答案并没有解决我的问题。

我有一个带有设置的应用程序:

在此处输入图像描述

我希望在我的所有视图控制器中仅支持纵向/倒置方向,除非我想通过以下方式播放视频:

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];
}

播放视频时MPMoviePlayerViewController,我希望支持所有方向。
需要你的帮助。

4

2 回答 2

2

您应该通过以下方式允许轮换:

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

IOS 6:

- (NSUInteger)supportedInterfaceOrientations
{

    return UIInterfaceOrientationMaskAll;
}

将代码放在调用播放器的 .m 文件中

于 2013-01-25T14:13:11.103 回答
0

大家好,我有同样的问题我解决了 -

您需要先更改 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 中正常运行。谢谢

于 2014-04-08T08:18:24.637 回答