xcode 如何让我的活动指示器视图覆盖所有屏幕?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10156995/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:58:27  来源:igfitidea点击:

How to make my activity indicator view cover all screen?

iphoneobjective-ciosxcode

提问by Richard Knop

So when a user clicks on a button in my app, I would like to create a new view with an activity indicator and cover the whole screen with it until the button action finishes.

因此,当用户单击我的应用程序中的按钮时,我想创建一个带有活动指示器的新视图,并用它覆盖整个屏幕,直到按钮操作完成。

However, my activity indicator view is covering only inside of a table view, it looks like this:

但是,我的活动指示器视图仅覆盖表视图内部,如下所示:

enter image description here

在此处输入图片说明

How to make it cover whole screen? Including the navigation controller and table view toolbar.

如何让它覆盖整个屏幕?包括导航控制器和表格视图工具栏。

Here is my code I use to create the view:

这是我用来创建视图的代码:

self.overlayView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.overlayView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
self.activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
self.activityIndicator.center = self.overlayView.center;
[self.overlayView addSubview:self.activityIndicator];
[self.activityIndicator startAnimating];
[self.tableView addSubview:self.overlayView];

回答by CodaFi

Change

改变

[self.tableView addSubview:self.overlayView];

To

[self.navigationController.view addSubview:self.overlayView];

Set the overlay's rect accordingly.

相应地设置覆盖的矩形。

回答by shabbirv

Do this:

做这个:

[[UIApplication sharedApplication].keyWindow addSubview:self.overlayView];