【问题标题】:iOS 8 Transparent View with non-transparent subviews带有非透明子视图的 iOS 8 透明视图
【发布时间】:2014-12-03 09:44:47
【问题描述】:

我想在 UIImageView 上放置非透明内容。所以我有一个包含所有内容的透明背景视图。我把它放在了imageview的顶部。我已将此视图的背景颜色设置为 clearColor,但仍然无法获得所需的效果。

这显然可以通过 iOS 6 SDK 实现,但现在我正在尝试使用 iOS 8 SDK,但它并没有满足我的需求。

查看此应用的屏幕截图

我正在尝试使用 iOS 8 SDK 实现类似的效果(半透明视图)。但是我需要将不透明度设置为非常低的值,这使得视图几乎透明。我所能实现的只是非常小的透明度(即使我设置了 0 也像 alpha 0.9)。

【问题讨论】:

  • 显示一些代码。您究竟如何呈现您想要的“透明”视图?
  • 以上截图来自我目前正在开发的同一个应用程序。我无法在 iOS 8 中获得同样的效果。已经工作的代码不再工作了。上面截图的透明视图有 0.6 alpha 和 clearColor 设置为它的容器视图。现在设置 clearColor 不再起作用了。它添加了一种暗灰色,几乎不透明
  • 好的,但是您仍然没有添加任何代码。
  • OMFG 你有什么问题?
  • @Andy 我是谁?还是 OP?

标签: ios objective-c iphone


【解决方案1】:

这可以通过使用 iOS 8 上提供的 UIVisualEffectUIVisualEffectView 来实现。

正如你所说,这将提供一个透明的视图,而不影响子视图。

试试这个

UIVisualEffectView *blurredView =[[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
[blurredView addSubview:self.mySubView];

您也可以添加子视图和图像视图。

【讨论】:

  • 谢谢。但我需要视图是透明的而不是模糊的。我需要视图后面的内容清晰可见而没有毛刺。还需要支持iOS 7
  • 哦!可以通过将父视图的颜色设置为清除颜色来完成[self.myParentView setBackgroundColor:[UIColor clearColor]];
  • 现在不行了。我已经尝试过,它在 iOS 6 中工作,但现在不行。在我看来,我有(从下到上)Imageview-> uiview -> uiscrollview -> contents
  • 并且我已经将所有可能的视图背景颜色设置为 clearColor(内容颜色除外)
  • 哦!可以通过将父视图的颜色设置为清除颜色来完成[self.myParentView setBackgroundColor:[UIColor clearColor]];并添加另一个具有相同大小且具有所需颜色的视图,并将 alpha 设置为该视图: [self.myParentView setBackgroundColor:[UIColor clearColor]]; UIView* viewTransparent=[[UIView alloc]initWithFrame:self.myParentView.bounds]; [viewTransparent setAlpha:0.5] [self.myParentView addSubView:viewTransparent];
【解决方案2】:

按顺序添加你需要的视图,类似下面的代码...

UIImageView* bottomImgView = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
bottomImgView.image=[UIImage imageNamed:@"yourImg.png"];
[self.view bottomImgView];

UIView* topTransparentView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
topTransparentView.backgroundColor = [UIColor clearColor];
[bottomImgView addSubview:topTransparentView];

UIView* subView = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
subView.backgroundColor = [UIColor blueColor];
[topTransparentView addSubview:subView];

【讨论】:

    猜你喜欢
    • 2010-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多