1

For iOS 7, I had status bar problem. For that I solved it by using below code in Appdelegate

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
    [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleLightContent];
    self.window.clipsToBounds =YES;
    self.window.frame =  CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
    self.window.bounds = CGRectMake(0,0, self.window.frame.size.width, self.window.frame.size.height);
}

All is working perfectly.

Only it gives problem while taking photo.

When I open camera or photo gallery, I still see status bar and because of that I see half of the navigation title as shown below.

enter image description here

Any idea how can I overcome this error?

The problems are :

  1. Photo Gallery/ Camera comes like above image

  2. If I click cancel, my view is shifted 20px up automatically.

Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276

3 Answers3

5

Instead of:

self.window 

Use this:

[[self view] window]

Try Like this:

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
    [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleLightContent];
    self.view.window.clipsToBounds =YES;
    self.view.window.frame =  CGRectMake(0,20,self.view.window.frame.size.width,self.view.window.frame.size.height-20);
    self.view.window.bounds = CGRectMake(0,0, self.view.window.frame.size.width, self.view.window.frame.size.height);
}
Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276
PR Singh
  • 653
  • 5
  • 15
1

I guess you are using the UINavigationController. There is nothing to do with the frame nor to do something with the Status Bar, If you are using UINavigationController. Please prefer the below code to set the UINavigationController along with Status bar set up. Else you can display the code, Will help you fix this.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[UIApplication sharedApplication] setStatusBarHidden:NO];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.viewController = [[ExViewController alloc] initWithNibName:@"ExViewController" bundle:nil];
    self.window.rootViewController = self.viewController;

    self.mainViewNavigation = [[UINavigationController alloc] initWithRootViewController:self.viewController];
    self.window.rootViewController = mainViewNavigation;


    [self.window addSubview:self.mainViewNavigation.view];
    [self.window makeKeyAndVisible];
    return YES;
}
Abdul Naveed
  • 567
  • 2
  • 9
0

I faced this problem wih one of my project. We didn't even have the xib for many classes. So all I could do is reset the frame once again in the delegate functions.

   [self.navigationController dismissViewControllerAnimated:YES
                                              completion:^{
                                                  [self.navigationController.view setFrame:CGRectMake(self.navigationController.view.frame.origin.x, [UIApplication sharedApplication].statusBarFrame.size.height, self.navigationController.view.frame.size.width, [[UIScreen mainScreen] bounds].size.height-[UIApplication sharedApplication].statusBarFrame.size.height)];
                                              }];

I put this in the finish/cancel delegate methods of photo/camera picket, mail picker.

Ramaraj T
  • 5,184
  • 4
  • 35
  • 68
  • Why do you need to reset when you can tell the navigation controller what is its rootviewcontroller and so on.. The frame will be set by itself. I have done the same thing with out any reset. – Abdul Naveed Oct 23 '13 at 06:08
  • 1
    Thank u... Thank u... Thank u... Thank u... Thank u... Thank u... Thank u... Thank u... Thank u... Why you didn't met me yesterday ;) I was wasting 4 hours on it... thanks Man... – Fahim Parkar Oct 23 '13 at 06:09
  • @Suresh : I am facing now one problem... When I add some photo and try to add new photo again, all mess goes... when I tries to upload second image and click cancel or upload image, view gets resetted.. all goes to top – Fahim Parkar Oct 23 '13 at 06:18
  • You have to place the code in the imagePickerControllerDidCancel also. – Ramaraj T Oct 23 '13 at 06:32