基本的にTabBarアプリであるアプリ(私の最初のアプリ)に取り組んでいます。より正確には、次のようなものがあります: - ログイン ビュー コントローラー - タブ バー コントローラー (ログインが完了したとき) - TabBar の最初のアイテムが縦向きから横向きに切り替わるときに使用される横向きビュー コントローラー。
そのため、最初のタブにいるときは、横向きビューに移動して他のデータを表示できるようにする必要があります。私のタブ バー コントローラーでは、これらのメソッドを実装しました。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if([self selectedIndex] == 0)
return YES;
return NO;
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
// Get AppDelegate
MyAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
// Remove TabBarView and add graph Landscape View
[self.view removeFromSuperview];
[delegate setSubViewLandscapeViewController];
}
}
デリゲートでは、setSubViewLandscapeViewController と setSubViewTabBarController を実装しました。
- (void)setSubViewTabBarViewController {
[window addSubview:[tabBarController view]];
}
- (void)setSubViewGraphLandscapeViewController {
[window addSubview:[landscapeViewController view]];
}
私は、landscapeViewController をランドスケープ モードでのみ表示したいので、(自分の landscapeViewController で):
- (void)viewWillAppear:(BOOL)animated {
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
NSLog(@"willRotateToInterfaceOrientation");
}
これの一部は正常に機能します。つまり、縦向きから横向きへの切り替えは問題なく (最初のタブにいるとき)、SuperView から tabbarcontroller が削除され、代わりに横向きビューがサブビューとして追加されます。
問題は...ポートレートモードに戻す方法がわかりません(そして、デリゲートのsetSubViewTabBarViewControllerを使用して、前のコントローラーであるtabBarコントローラーをロードします)。willRotateToOrientation、willRotateFromOrientation、..デバイスを実際に横向きビューから移動すると、トリガーされないようです...
要するに、私が横向きのビューにいるとき、タブバー ビューに戻るにはどうすればよいかわかりません... このビューに入ると、横向きのビューで立ち往生しています。
ご協力ありがとうございました。
リュック