私は数多くのトピックを検索し、最終的に有効な解決策を見つけました。
私の例では、2 つの VC があります。
A -> Nav 内に組み込まれている VC。Controller であり、Portrait ビューのみをサポートする必要があります。
B -> VC 内に埋め込まれておらず、ランドスケープのみをサポートする必要がある VC。
ビューAからビューBに(ボタンを押すことで)移動し、特定の向きがまだ正しい状態でビューAに戻りたいと思います。
I. UINavigationController のカテゴリを作成し、.m ファイルに次のように記述します (コードは自動的に呼び出されます)。
- (NSUInteger)supportedInterfaceOrientations
{
NSLog(@"supportedInterfaceOrientations = %d ", [self.topViewController supportedInterfaceOrientations]);
return [self.topViewController supportedInterfaceOrientations];
}
- (BOOL)shouldAutorotate
{
return self.topViewController.shouldAutorotate;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// You do not need this method if you are not supporting earlier iOS Versions
return [self.topViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
Ⅱ.A と B の間にモーダル セグエを作成し、その後 B と A の間に別のモーダル セグエを作成します。
III. 各 View Controllers .m ファイルに次の内容を書き留めます。
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
また
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
このコードを追加した後。単一ビュー B の向きを変更できます。