简体   繁体   English

将UIView添加到UIWindow无法正常工作

[英]Adding UIView to UIWindow not working

I am trying to add a UIView to UIWindow using the appDelegate I am using this code: 我正在尝试使用appDelegateUIWindow添加UIView我正在使用此代码:

NSArray *myViewArray = [[NSBundle mainBundle] loadNibNamed:@"View" owner:self options:nil];

UIView *myView = myViewArray[0];

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

myView.frame = CGRectMake(0, 0, 258, 564);
[myView setTag:100];
[window addSubview:myView];

However this doesn't work. 但是这不起作用。 If I add it to my self.view it works fine. 如果我将它添加到我的self.view它工作正常。 However, I want this view to be onto of all other views when it appears. 但是,我希望此视图在出现时显示在所有其他视图上。

What am I doing wrong here? 我在这做错了什么?

Edit 编辑

I used code from my last SO question: How to add a UIImage below UIBarButton item 我使用了上一个SO问题中的代码: 如何在UIBarButton项目下添加UIImage

There it worked fine, no problems. 它工作正常,没有问题。

However in this new project which only has a viewDidLoad method and one controller its not working. 但是在这个只有viewDidLoad方法的新项目中,一个控制器无法正常工作。

确保在初始化窗口后添加子视图,设置其rootViewController并调用makeKeyAndVisible。

尝试使用[window bringSubViewToFront:myView];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM