如何在 UIViewController 中添加一个子视图来覆盖 UINavigation bar?

How to add a subview to cover UINavigation barin UIViewController?

你好,我想在我当前的视图控制器之上添加一个 UIView。所以我喜欢这个。

- (void)viewDidLayoutSubviews
{

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

但这是在我的视图顶部添加但在我的导航后面 bar.Istill 可以清楚地看到导航栏标题和导航菜单项,也可以单击导航栏项。但我也想从我的新视图中覆盖这个导航栏。 我怎样才能做到这一点?请帮我。 谢谢

使用此代码

UIWindow *window = [[UIApplication sharedApplication] keyWindow];
CGSize screenBounds = [UIScreen mainScreen].bounds;
UIView *vwOverlay=[[UIView alloc] initWithFrame: screenBounds];
[vwOverlay setBackgroundColor:[UIColor blackColor]];
[vwOverlay setAlpha:0.5];
[window addSubview:vwOverlay];