热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

当主页按钮按下视图原点改变?-whenhomebuttonpressedvieworiginchanged?

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视图用于更改状态栏的颜色。这是上面代码的结果:

enter image description here

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,如下图所示:

enter image description here

what's the problem ?thanks

有什么问题?谢谢

1 个解决方案

#1


0  

Create a UIView programatically on method

以编程方式创建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];

}

or

Create a view using storyboard and set the x as 0, y value as 20,width and height based on the screen size

使用情节提要板创建视图,并根据屏幕大小将x设置为0,y值为20,宽度和高度

@IBOutlet UIView *customView;

set the outlet in the storyboard,

设置故事板中的插座,

Then set the background color of the custom view to redcolor and main view to white color

然后将自定义视图的背景颜色设置为红色,将主视图设置为白色

self.view.backgroundColor = [UIColor whiteColor];
customView.backgroundColor = [UIColor redColor];

推荐阅读
author-avatar
可乐加冰2502937787
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有