iPhone 电影仅旋转子视图

发布于 2024-11-17 04:20:16 字数 1579 浏览 0 评论 0原文

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

模拟器被迫旋转,但电影却没有。下面是一个示例:

Movie Player Error

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

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 setOrientation UIInterfaceOrientationLandscapeRight];但是编译器给了我一个错误并且没有任何反应

I am working on an app that disallows rotation unless a movie is playing. I have the app rotated just fine, but the issue comes about when I try to view the movie.

The simulator is forced to rotate, but the movie does not. An example of this is below:

Movie Player Error

I can't figure out how to rotate the movie too. I am looking to rotate only the subview. My code is below:

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

EDIT: I tried [moviePlayer setOrientation UIInterfaceOrientationLandscapeRight]; but the complier gives me an error and nothing happens

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

口干舌燥 2024-11-24 04:20:16

您使用的是MPMoviePlayerController吗?

尝试使用MPMoviePlayerViewController。该类是一个 UIViewController,应该自行处理旋转。

只需调用方法 [moviePlayerViewController moviePlayer]; 即可从视图控制器获取 MPMoviePlayerController;

Are you using the MPMoviePlayerController?

Try the MPMoviePlayerViewController. That class is a UIViewController and should handle the rotation on it self.

You get the MPMoviePlayerController from the view controller by just calling the method [moviePlayerViewController moviePlayer];

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文