4

以前のiOSバージョンでは、ビデオは自動的に回転していましたが、iOS6ではそうではありません。presentMoviePlayerViewControllerAnimatedは以前にそれを行うように設計されていましたが、MPMoviePlayerViewControllerに自動的に回転するように指示するにはどうすればよいですか?

MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
4

3 に答える 3

10

appdelegate.m で:

- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    if ([[self.window.subviews.lastObject class].description isEqualToString:@"MPMovieView"]) {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
    else {
        return UIInterfaceOrientationMaskPortrait;
    }
}

ちょっとハックですが、うまくいきます...

于 2013-04-12T12:20:34.297 に答える
6

私はちょうど同じ問題に遭遇しました。James Chen の解決策は正しいのですが、アプリ デリゲートで application:supportedInterfaceOrientationsForWindow をオーバーライドし、rootView コントローラーが MPMoviePlayerViewController をモーダルに提示している場合は allButUpsideDown を返すという、もう少し単純なことをしてしまいました。確かにハックであり、すべての状況に適しているとは限りませんが、すべてのビュー コントローラーを変更する必要がなくなりました。

- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    return [rootViewController.modalViewController isKindOfClass:MPMoviePlayerViewController.class ] ? UIInterfaceOrientationMaskAll : UIInterfaceOrientationMaskAllButUpsideDown;
}
于 2012-11-01T18:48:26.577 に答える
4

これに限らないMPMoviePlayerViewController。iOS 6 から自動回転が変更されました。iOS 6 の Autorotate の動作がおかしい を参照してください。

アプリを iOS 6 以前のように動作させるには、アプリがすべての向きをサポートするようにし ( UISupportedInterfaceOrientationsplist で編集)、回転をサポートしない他のすべてのビュー コントローラーに対して、このメソッドをオーバーライドして NO を返す必要があります。

- (BOOL)shouldAutorotate {
    return NO;
}

デフォルトでMPMoviePlayerViewControllerはすべての向きをサポートしているため、これで十分に機能するはずです。

于 2012-09-26T02:45:17.437 に答える