作者:可乐加冰2502937787 | 来源:互联网 | 2023-05-16 22:59
IhavethiscodeinviewDidLoad:我在viewDidLoad中有这个代码:[self.navigationControllersetNavigationBarHi
I have this code in viewDidLoad:
我在viewDidLoad中有这个代码:
[self.navigationController setNavigationBarHidden:YES];
self.edgesForExtendedLayout = UIRectEdgeNone;
self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight;
self.view.backgroundColor = [UIColor whiteColor];
//we need to add white background behind the status bar
CGFloat statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;
UIView* statusBarWhiteBackGround = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, statusBarHeight)];
[statusBarWhiteBackGround setBackgroundColor:[UIColor whiteColor]];
[self.view addSubview:statusBarWhiteBackGround];
UIView * redBackGroundColor = [[UIView alloc] init];
[redBackGroundColor setBackgroundColor:[UIColor redColor]];
redBackGroundColor.frame =CGRectMake(0,statusBarHeight , self.view.frame.size.width, self.view.frame.size.height-statusBarHeight);
[self.view addSubview:redBackGroundColor];
statusWhiteBackGround view is used to change the color of the status bar. here is the result of the above code:
statusWhiteBackGround视图用于更改状态栏的颜色。这是上面代码的结果:
but when the app enter background and then back to foreground, the redBackGroundColor view change it's orging.y as you can see in the bellow picture:
但当应用程序进入背景然后返回前景时,redBackGroundColor视图会更改它的orging.y,如下图所示:
what's the problem ?thanks
有什么问题?谢谢
1 个解决方案