How can I add a subview under statusbar and on top of Navigationbar in iOS?

143 Views Asked by At

I am trying to add a subview in between statusbar and navigationbar, so I have set the y position = 0 and after that I am reducing UIApplication Keywindow size so that it would free up space on top.

but the status bar is looking odd and it has been shifted too. enter image description here

The navigationbar is shifted downwards, that's okay. but I need to show proper statusbar also. Here is my code.

    float yPosition = 0;
    CGRect fr = CGRectMake(0, yPosition, UIScreen.mainScreen.bounds.size.width, 40);
    
    runningCallView.frame = fr;
    
    [UIApplication sharedApplication].keyWindow.frame = CGRectMake(0, 40, UIScreen.mainScreen.bounds.size.width, UIScreen.mainScreen.bounds.size.height-40);
    [[UIApplication sharedApplication].keyWindow.rootViewController.view addSubview:runningCallView];```

Can anyone please help on this. Thank you.
1

There are 1 best solutions below

0
MMSmmsbd On

I've solved the problem. Now instead of shifting keyWindow downwards, I've shifted down the rootviewController.

[UIApplication sharedApplication].keyWindow.rootViewController.view.frame = CGRectMake(0, shiftDownwards, UIScreen.mainScreen.bounds.size.width, UIScreen.mainScreen.bounds.size.height-shiftDownwards);

and added a statusbar subView to show a fake subview on top. Also UiWindow needed to be subclasses to detect touch on the extra addedView.

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event