简体   繁体   中英

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

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. 在此处输入图像描述

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM