私は非常に奇妙な問題を抱えています。ビデオを横向きモードで表示したいのですが、機能しないようです。いつも横向きに見せられなくても、少なくとも大丈夫に見せたいし、それも出来ない!! これが私のコードです:
#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 direction = Landscape(右のホームボタン)を挿入してみました
私が得ているのは、アプリを横向きモードで起動した場合、iPadを縦向きに回転させても、横向きのままであるということです。すごい!しかし、アプリをポートレートモードで起動すると、ビデオはポートレートモードで表示されます。横向きに回転すると、縦向きに戻すことはできません。これは良いことですが、縦向きで開始したくありません。
編集2
さて、これはさらに奇妙です。iPhoneで試してみるとうまくいきます。アプリを横向きと縦向きのどちらで起動しても、動画は常に横向きで表示されます。
しかし、iPadで試してみると、EDIT 1の問題が発生します...:S
何か案は?
ありがとう!