当按下主页按钮时,视图原点改变了吗?
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];
}
或
使用storyboard创建视图,x为0,y为20,宽高根据屏幕尺寸设置
@IBOutlet UIView *customView;
在故事板中设置出口,
然后将自定义视图的背景色设置为红色,主视图设置为白色
self.view.backgroundColor = [UIColor whiteColor];
customView.backgroundColor = [UIColor redColor];
我在 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];
}
或
使用storyboard创建视图,x为0,y为20,宽高根据屏幕尺寸设置
@IBOutlet UIView *customView;
在故事板中设置出口,
然后将自定义视图的背景色设置为红色,主视图设置为白色
self.view.backgroundColor = [UIColor whiteColor];
customView.backgroundColor = [UIColor redColor];