【问题标题】:ios - Need navigation bar with alpha but NO translucent blurios - 需要带有 alpha 但没有半透明模糊的导航栏
【发布时间】:2014-09-11 08:02:37
【问题描述】:

是否可以将导航栏设置为黑色,alpha 为 0.80f,并且没有半透明模糊?并在栏后面显示视图?

到目前为止,我已经尝试将背景设置为带有 alpha 的图像。然而,背景看起来仍然有点不透明,我看不到栏后面的景色......除非我将半透明设置为“是”。但是将 translucent 设置为 YES 也会增加模糊,这是我不想要的。

这就是我正在做的:

CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);

UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetFillColorWithColor(context, [UIColor colorWithWhite:RGBValue(0.0f) alpha:0.80f].CGColor);
CGContextFillRect(context, rect);

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

[[UINavigationBar appearance] setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];

 UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:[MyViewController new]];
 [navController.navigationBar setTranslucent:NO];

【问题讨论】:

  • 将栏设置为不透明会使其...嗯,不透明,这不是您想要的。将图像设置为背景确实应该消除模糊。你是说尽管有背景图片你还是看到模糊?
  • 我希望导航栏对某个 alpha 透明。使用 alpha 设置背景图像似乎并不能解决问题。我的意思是我希望栏是透明的,而不是半透明的。

标签: ios ios7 uinavigationbar


【解决方案1】:

啊,我想我解决了。我只需将 translucent 设置为 YES 即可。

似乎如果导航栏设置了背景图像,那么将 translucent 设置为 YES 将允许背景图像显示出来,而不会实际添加任何模糊。这正是我想要的。

【讨论】:

    猜你喜欢
    • 2016-03-10
    • 2014-11-07
    • 2017-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多