复制 UIAlertView 时;背景不一样

When replicating UIAlertView; background is not the same

我正在创建自定义 UIAlertView(来自 UIView)。我试图获得相同的背景效果(当背景视图变暗时)。所以我创建了一个新的黑色 UIView,不透明度为 .5,并将其添加到背景中。

问题是,我有一个标签栏。当黑色 UIView 覆盖背景时,它不会覆盖 UIView。这里有 2 张图片展示了我的问题:

标准UIAlertView背景:

自定义UIAlertView背景

这是我创建背景的代码view:

UIView *backgroundView = [[UIView alloc] initWithFrame:self.view.frame];
[backgroundView setBackgroundColor:[UIColor blackColor]];
[backgroundView setAlpha:0.5f];
[self.view addSubview:backgroundView];

如何让 UIView 覆盖标签栏?

尝试将 backgroundView 添加到 self.view.window,而不是 self.view。