Question

I added the following code in the AppDelegate implementor function didFinishLaunchingWithOptions

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {

    [application setStatusBarStyle:UIStatusBarStyleLightContent];

    self.window.clipsToBounds =YES;

   self.window.frame =  CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(applicationDidChangeStatusBarOrientation:)
                                                 name:UIApplicationDidChangeStatusBarOrientationNotification
                                               object:nil];

}

as well as this function that is being called:

- (void)applicationDidChangeStatusBarOrientation:(NSNotification *)notification
{
    int a = [[notification.userInfo objectForKey: UIApplicationStatusBarOrientationUserInfoKey] intValue];
   int w = [[UIScreen mainScreen] bounds].size.width;
    int h = [[UIScreen mainScreen] bounds].size.height;

    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
    UIDeviceOrientation orientationa = [[UIDevice currentDevice] orientation];

   if (orientation==4)
    {
        self.window.frame =  CGRectMake(20,0,w-20,h+20);
    }else if(orientation==1)
    {
        self.window.frame =  CGRectMake(0,20,w,h);
    }else
    {
       self.window.frame =  CGRectMake(-20,0,w+20,h+20);
    }
}

This works with getting the status bar to not overlap even when rotating but when clicking on a button that makes a request to the backend it changes and overlaps until it is rotated again, anyone knows why this might happen? I suspect it could be something to do with the ECSlidingViewController?

Was it helpful?

Solution

Try this code & set this in Info.plist View controller-based status bar appearance = NO

- (void) viewDidLoad
{
    [super viewDidLoad];

    float systemVersion = [[[UIDevice currentDevice] systemVersion] floatValue];

    if (systemVersion >= 7.0f)
    {
        CGRect tempRect;

        for (UIView *sub in [[self view] subviews])
        {
            tempRect = [sub frame];

            tempRect.origin.y += 20.0f; //Height of status bar

            [sub setFrame:tempRect];
        }
    }
}

OTHER TIPS

In order to support ios7 with ECECSlidingViewController whenever you are usign navigation controller uncheck allthe options to extend edges from the View controller XIB and where you are not using navigation controller you can using the below code in the Viewcontroller.m file.

-(void)viewDidLayoutSubviews
{
    if([[[UIdevice currentdevice]systemversion]floatvalue] >=7.0f){
    CGRect screen = [UIScreen mainscreen]bounds];
    CGRect frame = self.view.frame;
    frame.origin.y = 20.0f;
    frame.size.height = screen.size.height - 20;
}
  [self.view layoutsubviews];
}

and in view didfinishlaunching add the following

[application setStatusbarStyle:UIStatusBarStyleTranslucent];

and in plist file add ViewControllerBasedStatuschangedAppearence to NO

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top