UINavigationControllerのサブクラスでLandscapeLeft固定にし、
AppDelegate.csでWindow.RootViewControllerに設定後、MyViewControllerで青い四角を真ん中に配置しています。
横画面からの起動だときちんと画面中央に表示されますが、
縦画面からの起動だと中央には表示されません。なぜでしょうか?
▼AppDelegate.cs
c#
1 public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) 2 { 3 Window = new UIWindow(UIScreen.MainScreen.Bounds); 4 MyNavigationController navigationController = new MyNavigationController(); 5 Window.RootViewController = navigationController; 6 Window.MakeKeyAndVisible(); 7 8 MyViewController nextViewController = new MyViewController(); 9 navigationController.PushViewController(nextViewController, true); 10 11 return true; 12 }
▼MyNavigationController.cs
c#
1 class MyNavigationController : UINavigationController 2 { 3 public override UIInterfaceOrientation PreferredInterfaceOrientationForPresentation() 4 { 5 Console.WriteLine("PreferredInterfaceOrientationForPresentation"); 6 return UIInterfaceOrientation.LandscapeLeft; 7 } 8 9 public override bool ShouldAutorotate() 10 { 11 Console.WriteLine("ShouldAutorotate"); 12 return false; 13 } 14 15 public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations() 16 { 17 Console.WriteLine("GetSupportedInterfaceOrientations"); 18 return UIInterfaceOrientationMask.LandscapeLeft; 19 } 20 21 }
▼MyViewController.cs
c#
1 public override void ViewDidLoad() 2 { 3 base.ViewDidLoad(); 4 5 UIView blueView = new UIView() 6 { 7 Bounds = new CGRect(0, 0, 100, 100), 8 BackgroundColor = UIColor.Blue, 9 }; 10 blueView.Center = View.Center; 11 View.AddSubview(blueView); 12 }
◆環境
▼実機デバイス
iPad 9.7インチ Wi-Fiモデル 32GB MRJN2J/A
▼Windows 10
Visual Studio Community 2017 Version 15.9.11
Xamarin 4.12.3.83
Xamarin.iOS and Xamarin.Mac SDK 12.4.0.64
▼Mac mini(Late 2014)
macOS Majave 10.14.4
Xcode 10.2.1
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/06/14 16:03