我有一个非常奇怪的问题。我希望视频以横向模式出现,但我似乎无法让它工作。即使我不能让它总是显示风景,至少我希望它显示好,我也做不到!这是我的代码:
#import "SplashViewController.h"
#import "MainViewController.h"
#import "MediaPlayer/MediaPlayer.h"
@interface SplashViewController ()
@property (nonatomic, retain) NSTimer *timer;
@end
@implementation SplashViewController
@synthesize timer = _timer;
-(BOOL)shouldAutorotateToInterfaceOrientation:UIInterfaceOrientation)toInterfaceOrientation
{
return YES;
}
- (id)init
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self = [self initWithNibName:@"SplashViewController_iPhone" bundle:nil];
} else {
self = [self initWithNibName:@"SplashViewController_iPad" bundle:nil];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self.navigationController setNavigationBarHidden:YES];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSString *url = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"intro.mp4"];
playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:[playerViewController moviePlayer]];
[playerViewController shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationLandscapeRight];
[self.view addSubview:playerViewController.view];
//play movie
MPMoviePlayerController *player = [playerViewController moviePlayer];
player.scalingMode = MPMovieScalingModeAspectFill;
[player play];
}
- (void) movieFinishedCallback:(NSNotification*) aNotification {
MPMoviePlayerController *player = [aNotification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[player stop];
[player.view removeFromSuperview];
[self loadMainView];
}
- (void)loadMainView
{
MainViewController *mainVC = [[MainViewController alloc] init];
[self.navigationController pushViewController:mainVC animated:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
@end
奇怪的事情来了……
如果我在 iPad 上以横向模式启动应用程序,视频会显示如下(请注意,顶部的栏不要比宽度短!:O)
如果我然后将 iPad 旋转到肖像,它看起来像这样:
但是,如果我在 iPad 上以纵向模式启动应用程序,视频会显示如下:
如果我然后将 iPad 旋转到横向,它看起来像这样:
太棒了!这个最终图像是我希望视频始终看起来的样子。有什么想法我可能做错了吗???
谢谢!
编辑 1
好的,通过@Tark 的回答,我能够解决播放器显示问题。现在无论我如何启动应用程序,它都显示良好。感谢那!!现在缺少的是始终横向模式。
我尝试了以下方法:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation==UIInterfaceOrientationLandscapeRight)
return YES;
return NO;
}
我还尝试在 Info.plist 中插入行 Initial interface orientation = Landscape (right home button)
我得到的是,如果我在横向模式下启动应用程序,如果我将 iPad 旋转到纵向,它会保持横向。伟大的!但如果我以纵向模式启动应用程序,视频将以纵向模式显示。一旦我将它旋转到横向,我就无法将它旋转回纵向,这很好,但我不希望它从纵向开始!
编辑 2
好吧,现在这更奇怪了。如果我在iPhone上试用,效果很好。无论我以横向还是纵向启动应用程序,视频始终以横向显示。
但是,如果我在iPad上尝试,则会出现 EDIT 1 中的问题......:S
有任何想法吗?
谢谢!