0

Rather than having to adjust every single XIB in my application, I was hoping to just resize the main view.

I did this in AppDelegate, with partial success:

if (kCFCoreFoundationVersionNumber > kCFCoreFoundationVersionNumber_iOS_6_1) {
    NSLog(@"iOs 7 detected");
    frame.origin.y += 20.0;
    frame.size.height -= 20.0;
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
}

self.window = [[[UIWindow alloc] initWithFrame:frame] autorelease];

The whole window moves down, the status bar shows nicely, BUT all my views are now 20 pixels too tall for the screen, as if my -20 for the height did not have any effect.

Does anyone have any idea as to how I can get the main window to be the right height?

Thanks!

Nico teWinkel
  • 870
  • 11
  • 19

2 Answers2

1

A possible solution could be the following: Instead of change the window size you could try to change the root view controller frame size. This solutions works for me . As a reference here is my code. I have added this inside my root view controller and I call it in my custom init method:

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
        {
            self.edgesForExtendedLayout = UIRectEdgeNone;
            CGRect frame=self.view.frame;
            frame.origin.y=20;
            frame.size.height-=20;
            self.view.frame=frame;
        }
rdiaz82
  • 996
  • 12
  • 31
  • Thanks for the suggestion. Unfortunately that doesn't seem to be working for me. I did check to make sure it's my root view controller (as called from AppDelegate), and I added an NSLog above the self.edges... line to make sure the code is being called. Most of the views in IB are autosizing, so I wonder if they just resize to reclaim the space. – Nico teWinkel Sep 25 '13 at 17:52
  • @rdiaz82 so you have to do this for every ViewController ? – onmyway133 Nov 24 '13 at 09:57
  • @entropy No, you should add this in each root view controllers in your app. – rdiaz82 Nov 28 '13 at 13:34
0

I got it to work by overriding the root viewcontroller and attach my "main" viewcontroller to that. Maybe there is a better way to work and do this, this is one way.

In your AppDelegate (applicationDidFinishLaunch method)

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
     //Override rootviewcontroller with an empty viewcontroller
     window.rootViewController = [[UIViewController alloc] init];

     //Setup my custom viewcontroller
     MyViewController *vc = [[MyViewController alloc] init];
     [vc setModalPresentationStyle:UIModalPresentationFullScreen];
     [window.rootViewController addChildViewController:vc];
     [window.rootViewController.view addSubview:vc.view];

      // Put in the desired size and position.
      vc.view.frame = CGRectMake(10.0, 100.0, 300.0, 100.0);

      ...

Just for fun. If you are doing your project with StoryBoard, same process but fetching the StoryBoard identifier. Note that in this case you must set the StoryBoard ID in Interface Builder for your main viewcontroller.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
     UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
        // Fetch viewcontroller from the storyboard ID that you have set in Interface Builder
        UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"MyMainViewController"];
        [vc setModalPresentationStyle:UIModalPresentationFullScreen];
        [window.rootViewController addChildViewController:vc];
        [window.rootViewController.view addSubview:vc.view];
        // Put in the disired size and position.
        vc.view.frame = CGRectMake(10.0, 100.0, 300.0, 100.0);

      ...
perborin
  • 234
  • 2
  • 10