iOS 7 アプリでは、「ビデオ プレーヤー」ビューで「横向き」の向きを許可する必要がある場合を除いて、アプリケーション全体の「サポートされているデバイスの向き」で「縦向き」のみを許可します。MvvmCross または MvxViewController でどうすればよいですか? これらの ShouldAutorotate()、GetSupportedInterfaceOrientations() メソッドを設定しようとしましたが、何もしません。「ビデオプレーヤー」ビューのポートレートモードでロックされたままになります。ビューの向きを設定する正しい方法を知っている人はいますか?
public class VideoPlayerView : MvxViewController
{
public override bool ShouldAutorotate()
{
return true;
}
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations()
{
return UIInterfaceOrientationMask.AllButUpsideDown;
}
public override UIInterfaceOrientation PreferredInterfaceOrientationForPresentation()
{
return UIInterfaceOrientation.LandscapeLeft;
}
public override void ViewDidLoad(bool animated)
{
Title = "Video";
base.ViewDidLoad(animated);
}
}
更新: この問題を解決する方法を見つけました。
ステップ 1) mvvmcross の場合、MvxModalNavSupportTouchViewPresenter から継承して新しい ViewPresenter をセットアップする必要があります。
ステップ 2) 次のコードを使用して、UINavigationController から継承する新しいナビゲーション コントローラーを作成します。
public override bool ShouldAutorotate()
{
return TopViewController.ShouldAutorotate();
}
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations()
{
var orientation = TopViewController.GetSupportedInterfaceOrientations();
return orientation;
}
ステップ 3) ステップ 1 で作成したばかりの新しい View Presenter 内で、CreateNavigationController メソッドをオーバーライドし、ステップ 2 で作成した新しい NavigationController を使用します。
ステップ 4) 向きを変更したい ViewController で、GetSupportedInterfaceOrientations メソッドをオーバーライドすることで変更できます。たとえば、私の VideoPlayerView には、以下のコードがあります。
public override bool ShouldAutorotate()
{
return true;
}
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations()
{
return UIInterfaceOrientationMask.AllButUpsideDown;
}