仅用于子视图的iPhone电影旋转

仅用于子视图的iPhone电影旋转,iphone,objective-c,xcode,rotation,mpmovieplayercontroller,Iphone,Objective C,Xcode,Rotation,Mpmovieplayercontroller,我正在开发一个不允许旋转的应用程序,除非正在播放电影。我的应用程序旋转得很好,但是当我试图观看电影时,问题就出现了 模拟器被迫旋转,但电影不旋转。这方面的一个例子如下: MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:finalURL]]; if ([moviePlayer respondsToSelector:@sele

我正在开发一个不允许旋转的应用程序,除非正在播放电影。我的应用程序旋转得很好,但是当我试图观看电影时,问题就出现了

模拟器被迫旋转,但电影不旋转。这方面的一个例子如下:

MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:finalURL]];
if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) {  
                // Use the 3.2 style API  
                moviePlayer.controlStyle = MPMovieControlStyleDefault;  
                moviePlayer.shouldAutoplay = YES;  
                [self.view addSubview:moviePlayer.view];  
                [moviePlayer setFullscreen:YES animated:YES];
             [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];

             // Rotate the view for landscape playback
             [[moviePlayer view] setBounds:CGRectMake(0, 0, 480, 320)];
             [[moviePlayer view] setCenter:CGPointMake(160, 240)];
             [[moviePlayer view] setTransform:CGAffineTransformMakeRotation(M_PI / 2)]; 

             // Set frame of movieplayer
             [[moviePlayer view] setFrame:CGRectMake(0, 0, 480, 320)];  

            } else {  
                // Use the 2.0 style API  
                moviePlayer.movieControlMode = MPMovieControlModeHidden;  
                [moviePlayer play];  
            } 
}

我也不知道如何旋转电影。我希望只旋转子视图。我的代码如下:

MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:finalURL]];
if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) {  
                // Use the 3.2 style API  
                moviePlayer.controlStyle = MPMovieControlStyleDefault;  
                moviePlayer.shouldAutoplay = YES;  
                [self.view addSubview:moviePlayer.view];  
                [moviePlayer setFullscreen:YES animated:YES];
             [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];

             // Rotate the view for landscape playback
             [[moviePlayer view] setBounds:CGRectMake(0, 0, 480, 320)];
             [[moviePlayer view] setCenter:CGPointMake(160, 240)];
             [[moviePlayer view] setTransform:CGAffineTransformMakeRotation(M_PI / 2)]; 

             // Set frame of movieplayer
             [[moviePlayer view] setFrame:CGRectMake(0, 0, 480, 320)];  

            } else {  
                // Use the 2.0 style API  
                moviePlayer.movieControlMode = MPMovieControlModeHidden;  
                [moviePlayer play];  
            } 
}

编辑:我尝试了
[moviePlayer设置方向UIInterfaceOrientationAndscapeRight]但是编译器给了我一个错误,什么也没有发生

你在使用
MPMoviePlayerController

请尝试使用
MPMoviePlayerViewController
。该类是UIViewController,应该自己处理旋转


只需调用方法
[MoviePlayerServiceControllerMoviePlayer],就可以从视图控制器获得MPMoviePlayerController

您是否正在使用MPMoviePlayerController

请尝试使用
MPMoviePlayerViewController
。该类是UIViewController,应该自己处理旋转


只需调用方法
[MoviePlayerServiceControllerMoviePlayer],就可以从视图控制器获得MPMoviePlayerController

你在真实设备上测试过吗?是的,它做同样的事情。你在真实设备上测试过吗?是的,它做同样的事情。是的,我忘了把它添加到问题中。它现在在那里。我是,我只是忘了把它添加到问题中。它现在在那里。