縦長の親から横長モードで ViewController をロードしたい。親は縦向きに固定され、向きは変わりませんが、親からプッシュされた子ビュー コントローラーは、デバイスの向きに関係なく、最初は縦向きをロードします (デバイスをさらに数回回転させると、向きが子に適切に設定されます)。 )。したがって、最初の時間自体に子を適切にロードする方法。
また
ViewWillAppear メソッドで使用できるように、向きをプログラムで設定する方法はありますか。ありがとう。
縦長の親から横長モードで ViewController をロードしたい。親は縦向きに固定され、向きは変わりませんが、親からプッシュされた子ビュー コントローラーは、デバイスの向きに関係なく、最初は縦向きをロードします (デバイスをさらに数回回転させると、向きが子に適切に設定されます)。 )。したがって、最初の時間自体に子を適切にロードする方法。
また
ViewWillAppear メソッドで使用できるように、向きをプログラムで設定する方法はありますか。ありがとう。
子 UIViewController で、次の 2 つのメソッドを設定します。
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeLeft;
}
親 UIViewController で次のことを行います。
[self.navigationController presentViewController:controller animated:YES completion:nil];
それ以外の:
[self.navigationController pushViewController:controller animated:YES];
子にナビゲーション バーを表示する場合:
DetailViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"];
controller.title = @"Child";
子ビュー コントローラーではなく、上記の 2 つのメソッドを使用して UINavigationController をサブクラス化する必要があります。
MyNavigationController *nav = [[MyNavigationController alloc] initWithRootViewController:controller];
[self.navigationController presentViewController:nav animated:YES completion:nil];
このサンプル プロジェクトを試してみてください........
これをビューで使用すると、表示された、または表示されます。
[[UIDevice currentDevice]performSelector:@selector(setOrientation:) withObject:(__bridge id)((void *)UIInterfaceOrientationLandscapeRight)];
その前に、.plist で 4 つの方向をすべて有効にします。
これを AppDelegate.m に追加します
- (NSUInteger)application:(UIApplication*)application
supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
UIViewController *cont=self.vc;
if([cont isKindOfClass:[YourClass class]])
{
NSUInteger orientations = UIInterfaceOrientationMaskLandscapeRight;
NSLog(@"Landscape");
return orientations;
}
NSUInteger orientations = UIInterfaceOrientationMaskPortrait;
return orientations;
}
私が正しければ、このメソッドを子View Controllerに追加するだけです
- (BOOL)shouldAutorotate {
return NO;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationLandscapeLeft / Right;
}
ビューの使用を提示するには
[self presentViewController:viewController...]
ビューは横向きモードで表示されます。