Search code examples
iosobjective-cios7uistatusbar

self.window not working inside view controller


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.


Solution

  • 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.