2

私は非常に奇妙な問題を抱えています。ビデオを横向きモードで表示したいのですが、機能しないようです。いつも横向きに見せられなくても、少なくとも大丈夫に見せたいし、それも出来ない!! これが私のコードです:

#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)

http://i.stack.imgur.com/kdPUP.png

次にiPadを縦向きに回転させると、次のようになります。

http://i.stack.imgur.com/iWK68.png

しかし、iPadを物理的にポートレートモードでアプリを起動すると、ビデオは次のように表示されます。

http://i.stack.imgur.com/9NXRY.png

次に、iPadを横向きに回転させると、次のようになります。

http://i.stack.imgur.com/pW6OK.png

これは素晴らしいです!この最終的な画像は、私がビデオに常に見せたいものです。私が間違っているかもしれないアイデアはありますか?

ありがとう!

編集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

何か案は?

ありがとう!

4

2 に答える 2

4

MPMoviePlayerViewControllerサブビューとして追加するときに、ビューのフレームを設定してみましたか?

...
playerViewController.view.frame = self.view.bounds;
[self.view addSubview:playerViewController.view];
...

アプリをランドスケープモードでのみ実行するには、アプリのplistで必要な方向のみを選択していることを確認する必要があります。Xcode 4では、ターゲット設定に便利なサポートされているインターフェイスの向きのセクションがあります。ここで横向きのみを選択していることを確認してください。それでも問題が解決しない場合は、ビュースタック内の表示されているすべてのコントローラーで自動回転を無効にしていることを確認する必要があります。

ここに画像の説明を入力してください

于 2012-12-19T17:11:32.150 に答える
0

shouldAutorotateToInterfaceOrientationはiOS6で非推奨になりました。supportedInterfaceOrientationsを使用してみましたか?

iOS 5と6をサポートしようとしている場合は、両方を使用する必要があると思います。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

私はこれをテストしていないので、それが価値があるものと考えてください。

于 2012-12-19T20:20:40.120 に答える