我花了2个小时找到正确的代码来解决我的方向问题
这是我的电影播放器​​代码。我需要这个特殊的视图以横向显示。

在appdelegate中,我设置了所有方向,在rootviewcontroller中,我设置为仅纵向,在我的movieplayer视图中设置为横向,但不设置运气。有人可以给我一些有关解决问题的意见吗?

- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
    return UIInterfaceOrientationMaskAll;
}


我的rootviewcontroller

- (BOOL)shouldAutorotate
{
    return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}


-(void)prepareIntroVideo
{
    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"designthinking_pt1" ofType:@"mp4"]];
    self.playercontroller = [[MPMoviePlayerController alloc] initWithContentURL:url];
    [self.playercontroller.view setFrame:CGRectMake(0, -20, 320, 480)];
    self.playercontroller.movieSourceType = MPMovieSourceTypeFile;
    self.playercontroller.scalingMode = MPMovieScalingModeAspectFill;
    self.playercontroller.fullscreen = NO;
       self.playercontroller.controlStyle = MPMovieControlStyleFullscreen;
    //playercontroller.controlStyle = MPMovieControlStyleFullscreen;
    self.playercontroller.view.userInteractionEnabled =YES;
    self.playercontroller.view.backgroundColor = [UIColor blackColor];
    self.playercontroller.shouldAutoplay = NO;

    //playercontroller.repeatMode = YES;
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlaybackComplete:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:self.playercontroller];


    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(applicationDidEnterBackground)
                                                 name: UIApplicationDidEnterBackgroundNotification
                                               object:[UIApplication sharedApplication]];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(applicationWillEnterForeground)
                                                 name:UIApplicationWillEnterForegroundNotification
                                               object:[UIApplication sharedApplication]];


    [self.playercontroller prepareToPlay];
    [self.view addSubview:self.playercontroller.view];
    [self.playercontroller setFullscreen:YES animated:YES];


    //[self.playercontroller stop];
    [self.view sendSubviewToBack:self.playercontroller.view];

}

- (BOOL)shouldAutorotate
{
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationLandscapeLeft;
}

最佳答案

您可以查看我的示例... https://dl.dropboxusercontent.com/u/19438780/testRotate.zip

我有2个带有导航控制器的控制器-纵向;为此,我将“分类”导航控制器(这里是肖像的“旋转”代码)

第三个控制器为风景型-如果要旋转它,必须以模态形式显示-相应地输入旋转代码。

10-08 05:57