0

在我的应用程序中,我想启动一个UIView重叠和变暗的整个屏幕,包括UINavigationBar,代码如下:

- (void)showInstruction
{
    self.holedView = [[JMHoledView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [self.view addSubview:self.holedView];
}

但实际上,只有在没有屏幕self.holedView的情况下才能使区域变暗。UINavigationBar我怎样才能做到这一点?

4

4 回答 4

2

您可以将视图作为子视图添加到窗口或导航控制器的视图。

[self.navigationController.view addSubview:yourView];

或者

[[[[UIApplication sharedApplication] delegate] window] addSubview:yourView];

创建视图的委托以在需要时将其从超级视图中删除

于 2015-05-06T07:57:28.863 回答
1

您可以使用变暗的透明图像并将其设置为导航栏的背景图像。

例如,在我的情况下,我制作了 alpha 0.2 的黑色透明图像并将其设置为导航背景图像,并使背景颜色清晰

 [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"black_patch.png"]
                                              forBarMetrics:UIBarMetricsDefault];
[UINavigationBar appearance].translucent = YES;
navController.view.backgroundColor = [UIColor clearColor];
于 2015-05-06T07:55:03.040 回答
0

我用它在主窗口中添加子视图:

[[UIApplication sharedApplication].keyWindow addSubview:view];
于 2015-05-06T08:00:30.513 回答
0

您可以将其添加到窗口中

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication  sharedApplication] delegate];
UIView *backgrView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height)];
backgrView.backgroundColor = [UIColor blackColor];
backgrView.alpha = 0.6;
[[appDelegate window] addSubview:backgrView];

或者

Try navigationBar.translucent = NO; , It is YES by default in iOS7.


 So you can add a version check like this:

 float systemVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
if (systemVersion >= 7.0)
{
 navigationBar.translucent = NO;
}
于 2015-05-06T08:11:38.443 回答