gpt4 book ai didi

ios - KeyWindow 添加子View,没有显示在最前面

转载 作者:行者123 更新时间:2023-11-28 21:10:31 26 4
gpt4 key购买 nike

我用keyWindow添加了一个subView,添加成功但是没有显示在screen hierarchy的最前面。

深灰色 View 是我添加的 View :

enter image description here

我的代码是:

@interface ViewController ()
{
LMLUpspringView *pop_v;
}

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];

pop_v = [[LMLUpspringView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];

UIWindow *keywindow = [[[UIApplication sharedApplication] delegate] window];

[keywindow addSubview:pop_v];

//[keywindow bringSubviewToFront:pop_v];
//[self.view addSubview:pop_v];

}

我试过使用 [keywindow bringSubviewToFront:pop_v] 把它带到前面。但是没有用。

如果我使用[self.view addSubview:pop_v],它会显示在前面。

最佳答案

您遇到这个问题,是因为您不知道viewDidLoad 方法和viewDidAppear: 方法之间的区别。

viewWillAppear:

Called before the view is added to the windows’ view hierarchy

viewDidAppear:

Called after the view is added to the view hierarchy

添加到窗口 View 层级的 Controller View 在viewWillAppear:viewDidAppear:之间,viewDidLoad之前viewWillAppear:,所以你不能那样做。您应该在 viewDidAppear: 中添加您的 View 。

关于ios - KeyWindow 添加子View,没有显示在最前面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43605689/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com