project_files/HedgewarsMobile/Classes/SettingsContainerViewController.m
changeset 6658 2cccf6b2b89d
parent 6319 b57a37a94ad3
child 6672 4f728ccdd06b
--- a/project_files/HedgewarsMobile/Classes/SettingsContainerViewController.m	Thu Feb 09 18:09:03 2012 +0100
+++ b/project_files/HedgewarsMobile/Classes/SettingsContainerViewController.m	Thu Feb 09 18:59:46 2012 +0100
@@ -21,10 +21,11 @@
 
 #import "SettingsContainerViewController.h"
 #import "SettingsBaseViewController.h"
+#import "MGSplitViewController.h"
 
 
 @implementation SettingsContainerViewController
-@synthesize baseController, activeController, splitViewRootController;
+@synthesize baseController, splitViewRootController;
 
 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
     return rotationManager(interfaceOrientation);
@@ -32,8 +33,8 @@
 
 
 -(void) viewDidLoad {
-    CGRect rect = [[UIScreen mainScreen] bounds];
-    self.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
+    CGRect screenRect = [[UIScreen mainScreen] safeBounds];
+    self.view.frame = screenRect;
 
     if (IS_IPAD()) {
         // the contents on the right of the splitview, setting targetController to nil to avoid creating the table
@@ -48,11 +49,11 @@
         UINavigationController *leftNavController = [[UINavigationController alloc] initWithRootViewController:leftController];
         [leftController release];
 
-        self.activeController = rightNavController;
-        self.splitViewRootController = [[UISplitViewController alloc] init];
+        self.splitViewRootController = [[MGSplitViewController alloc] init];
         self.splitViewRootController.delegate = nil;
-        self.splitViewRootController.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
+        self.splitViewRootController.view.frame = screenRect;
         self.splitViewRootController.viewControllers = [NSArray arrayWithObjects: leftNavController, rightNavController, nil];
+        self.splitViewRootController.showsMasterInPortrait = YES;
         [leftNavController release];
         [rightNavController release];
 
@@ -65,7 +66,7 @@
             [sbvc release];
         }
         self.baseController.targetController = nil;
-        self.baseController.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
+        self.baseController.view.frame = CGRectMake(0, 0, screenRect.size.height, screenRect.size.width);
 
         [self.view addSubview:self.baseController.view];
     }
@@ -78,8 +79,6 @@
 -(void) didReceiveMemoryWarning {
     if (self.baseController.view.superview == nil)
         self.baseController = nil;
-    if (self.activeController.view.superview == nil)
-        self.activeController = nil;
     if (self.splitViewRootController.view.superview == nil)
         self.splitViewRootController = nil;
     MSG_MEMCLEAN();
@@ -88,7 +87,6 @@
 
 -(void) viewDidUnload {
     self.baseController = nil;
-    self.activeController = nil;
     self.splitViewRootController = nil;
     MSG_DIDUNLOAD();
     [super viewDidUnload];
@@ -96,7 +94,6 @@
 
 -(void) dealloc {
     releaseAndNil(baseController);
-    releaseAndNil(activeController);
     releaseAndNil(splitViewRootController);
     [super dealloc];
 }
@@ -107,28 +104,35 @@
 // every time we add a uiviewcontroller programmatically we need to take care of propgating such messages
 // see http://davidebenini.it/2009/01/03/viewwillappear-not-being-called-inside-a-uinavigationcontroller/
 -(void) viewWillAppear:(BOOL)animated {
-    [self.activeController viewWillAppear:animated];
+    [self.splitViewRootController.detailViewController viewWillAppear:animated];
     [self.baseController viewWillAppear:animated];
     [super viewWillAppear:animated];
 }
 
 -(void) viewWillDisappear:(BOOL)animated {
-    [self.activeController viewWillDisappear:animated];
+    [self.splitViewRootController.detailViewController viewWillDisappear:animated];
     [self.baseController viewWillDisappear:animated];
     [super viewWillDisappear:animated];
 }
 
 -(void) viewDidAppear:(BOOL)animated {
-    [self.activeController viewDidAppear:animated];
+    [self.splitViewRootController.detailViewController viewDidAppear:animated];
     [self.baseController viewDidAppear:animated];
     [super viewDidLoad];
 }
 
 -(void) viewDidDisappear:(BOOL)animated {
-    [self.activeController viewDidDisappear:animated];
+    [self.splitViewRootController.detailViewController viewDidDisappear:animated];
     [self.baseController viewDidDisappear:animated];
     [super viewDidUnload];
 }
 
+-(void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
+    if (IS_IPAD() == NO)
+        return;
+
+    CGRect screenRect = [[UIScreen mainScreen] safeBounds];
+    self.splitViewRootController.masterViewController.view.frame = CGRectMake(0, 0, 320, screenRect.size.height);
+}
 
 @end