我在我的应用程序中有许多视频。有些使用MPMoviePlayerController,其他的则在UIWebView中使用YouTube。我希望我的应用程序完全是竖屏。然而,当有视频时,我想给用户翻转到横屏的选项(不是强制性的,而是可选的)。
我一直在网上搜索答案,但我还没有找到任何东西。
感谢您的帮助!
我一直在网上搜索答案,但我还没有找到任何东西。
感谢您的帮助!
我曾经遇到过同样的问题,通过在我的应用程序委托中添加以下内容解决了它,基本上只允许MPMoviePlayerViewController的子类横向方向:
#import <MediaPlayer/MediaPlayer.h>
@implementation UIViewController (orientationFix)
-(NSUInteger) supportedInterfaceOrientations
{
if ([[self class] isSubclassOfClass:[MPMoviePlayerViewController class]]) {
return UIInterfaceOrientationMaskLandscape;
}
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
if ([[self class] isSubclassOfClass:[MPMoviePlayerViewController class]]) {
return UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight;
}
return UIInterfaceOrientationPortrait;
}
@end
@implementation MyAppDelegate
.
.
.
@end
在AppDelegate中添加以下代码:
-(BOOL)shouldAutorotate { return NO; }
-(NSUInteger)supportedInterfaceOrientations
{
//LandScapeMode:- UIInterfaceOrientationMaskLandscape;
//PortraitMode:-
return UIInterfaceOrientationMaskPortrait
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
//LandScapeMode:- UIInterfaceOrientationLandscapeRight;
// ProtraitMode:-
return UIInterfaceOrientationPortrait
}
在应用程序委托中添加此代码。
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
//LandScapeMode:- UIInterfaceOrientationMaskLandscape;
//PortraitMode:-
return UIInterfaceOrientationMaskPortrait
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
//LandScapeMode:- UIInterfaceOrientationLandscapeRight;
// ProtraitMode:-
return UIInterfaceOrientationPortrait
}
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:theurl];
self.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
self.moviePlayer.controlStyle = MPMovieControlStyleNone;
self.moviePlayer.view.transform = CGAffineTransformConcat(self.moviePlayer.view.transform, CGAffineTransformMakeRotation(M_PI_2));
UIWindow *backgroundWindow = [[UIApplication sharedApplication] keyWindow];
[self.moviePlayer.view setFrame:backgroundWindow.frame];
[backgroundWindow addSubview:self.moviePlayer.view];
[self.moviePlayer play];
要么对它进行子类化并 -
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ //在此处返回横向 } 对于iOS6: shouldAutorotate 返回no
要么
使用这个:
MPMoviewPlayerController 全屏播放旋转,同时底层UIViewController仅支持纵向模式(不允许旋转)