Reputation: 880
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!
Upvotes: 0
Views: 3544
Reputation: 234
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); ...
Upvotes: 0
Reputation: 1026
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;
}
Upvotes: 1