我的整个应用程序都有视频。一些使用 MPMoviePlayerController,另一些使用 YouTube 的 UIWebView。我希望我的应用程序完全是纵向的。但是,我想让用户选择在有视频时翻转到横向(不是强制,而是可选)。
我一直在网上搜索答案,但我还没有找到任何答案。
谢谢你的帮助!
我的整个应用程序都有视频。一些使用 MPMoviePlayerController,另一些使用 YouTube 的 UIWebView。我希望我的应用程序完全是纵向的。但是,我想让用户选择在有视频时翻转到横向(不是强制,而是可选)。
我一直在网上搜索答案,但我还没有找到任何答案。
谢谢你的帮助!
I had the same issue and fixed it by adding this in my app delegate, basically allowing Landscape orientation only on subclasses of 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
要么子类化它 -
(BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation { //在此处返回风景 } 对于 ios6: shouldAutorotate return no
或者
用这个:
MPMoviewPlayerController 全屏播放旋转,底层 UIViewController 仅具有纵向模式(不允许旋转)
将此添加到应用程序委托中。
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
//LandScapeMode:- UIInterfaceOrientationMaskLandscape;
//PortraitMode:-
return UIInterfaceOrientationMaskPortrait
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
//LandScapeMode:- UIInterfaceOrientationLandscapeRight;
// ProtraitMode:-
return UIInterfaceOrientationPortrait
}
在 AppDelegate 中添加这些行。
-(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];