是否可以在彩色视图上方添加透明图层或视图?

时间:2015-08-12 10:39:28

标签: ios core-animation avfoundation

我正在使用AVFoundation框架扫描条形码,但这可能与我的问题无关。

我想要的是什么:

我希望绿色边框是透明的(不是黑色的黑色)。

enter image description here

这就是我所做的: 我有2个观看次数:backgroundView(占据整个屏幕)和highlightView,这是绿色边框,位于backgroundView之上(我使用了XIB作为尺寸和位置) :

self.highlightView.layer.borderColor = [UIColor greenColor].CGColor;
self.highlightView.layer.borderWidth = 3;
// this following line does not allow the square to be transparent
self.highlightView.layer.opacity = 0;

// relative to AVFoundation
_previewLayer.frame = _backgroundView.bounds;
[_backgroundView.layer addSublayer:_previewLayer];

_previewLayer.backgroundColor = [UIColor blackColor].CGColor;
_previewLayer.opacity = 0.3;

更新: xib(此处代表具有清晰颜色背景的方块),backgroundView具有黑色背景属性。)

enter image description here

1 个答案:

答案 0 :(得分:1)

正如我所提到的,你看错了方向。有多个帖子的问题类似于你的问题,答案相当不错。 (你必须学习和理解才能充分利用它们):

总结一下,您需要将半透明颜色应用于backgroundView图层,然后使用图层的mask属性来完成工作。< / p>

您可以找到许多教程,以便一起使用layermask进行学习。

希望这有帮助。