[英]when home button pressed view origin changed?
我在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视图用于更改状态栏的颜色。 这是上面代码的结果:
但是当应用程序进入背景然后又返回到前景时,redBackGroundColor视图将其更改为orging.y,如下面的图片所示:
有什么问题吗?谢谢
在方法上以编程方式创建UIView
-(void)viewDidLayoutSubviews{
screen=[[UIScreen mainScreen] bounds];
//Simple view
self.customView = [[CustomAlertOKView alloc]initWithFrame:CGRectMake(0, 20, screen.size.width, screen.size.height)];
[self.view addSubView:customView];
}
要么
使用情节提要板创建视图,并根据屏幕尺寸将x设置为0,y值设置为20,宽度和高度
@IBOutlet UIView *customView;
在情节提要中设置出口,
然后将自定义视图的背景色设置为红色,将主视图的背景色设置为白色
self.view.backgroundColor = [UIColor whiteColor];
customView.backgroundColor = [UIColor redColor];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.