如何显示与 UINavigationBar 重叠的 UIView
How to display a UIView which overlaps the UINavigationBar
在我的应用程序中,我想启动一个 UIView
重叠并调暗整个屏幕,包括 UINavigationBar
,代码如下:
- (void)showInstruction
{
self.holedView = [[JMHoledView alloc] initWithFrame:[UIScreen mainScreen].bounds];
[self.view addSubview:self.holedView];
}
但确实self.holedView
只能使屏幕上没有UINavigationBar
的区域变暗。我该怎么做?
您可以使用变暗的透明图片并将其设置为导航栏的背景图片。
例如,在我的例子中,我制作了 alpha 0.2 的黑色透明图像并将其设置为导航背景图像并将背景颜色设置为透明颜色
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"black_patch.png"]
forBarMetrics:UIBarMetricsDefault];
[UINavigationBar appearance].translucent = YES;
navController.view.backgroundColor = [UIColor clearColor];
您可以将视图作为子视图添加到 window 或导航控制器的视图。
[self.navigationController.view addSubview:yourView];
或
[[[[UIApplication sharedApplication] delegate] window] addSubview:yourView];
创建视图的委托以在需要时将其从父视图中删除
我用这个在主视图中添加子视图window:
[[UIApplication sharedApplication].keyWindow addSubview:view];
您可以将其添加到 window
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;
}
在我的应用程序中,我想启动一个 UIView
重叠并调暗整个屏幕,包括 UINavigationBar
,代码如下:
- (void)showInstruction
{
self.holedView = [[JMHoledView alloc] initWithFrame:[UIScreen mainScreen].bounds];
[self.view addSubview:self.holedView];
}
但确实self.holedView
只能使屏幕上没有UINavigationBar
的区域变暗。我该怎么做?
您可以使用变暗的透明图片并将其设置为导航栏的背景图片。
例如,在我的例子中,我制作了 alpha 0.2 的黑色透明图像并将其设置为导航背景图像并将背景颜色设置为透明颜色
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"black_patch.png"]
forBarMetrics:UIBarMetricsDefault];
[UINavigationBar appearance].translucent = YES;
navController.view.backgroundColor = [UIColor clearColor];
您可以将视图作为子视图添加到 window 或导航控制器的视图。
[self.navigationController.view addSubview:yourView];
或
[[[[UIApplication sharedApplication] delegate] window] addSubview:yourView];
创建视图的委托以在需要时将其从父视图中删除
我用这个在主视图中添加子视图window:
[[UIApplication sharedApplication].keyWindow addSubview:view];
您可以将其添加到 window
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;
}