Search code examples
iosios7ecslidingviewcontroller

Status bar overlapping when using ECSlidingViewController


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?


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];
            }
        }
    }