gpt4 book ai didi

objective-c - 使用 UIImage b/w iOS 屏蔽 UIView

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:17:06 24 4
gpt4 key购买 nike

我正在为 iPad 开发一个 iOS 应用程序。我想用黑白图像遮盖 UIView。所以图像的黑色部分是您可以看到的 View 。

如果像下面这样尝试不同的代码,但它们不起作用...

UIImage *_maskingImage = [UIImage imageNamed:@"ipadmask.jpg"];
CALayer *_maskingLayer = [CALayer layer];
_maskingLayer.frame = vistafunda.bounds;
[_maskingLayer setContents:(id)[_maskingImage CGImage]];
[vistafunda.layer setMask:_maskingLayer];
vistafunda.layer.masksToBounds = YES;

他们 ipadmask.jpg 是:enter image description here

感谢您的帮助!

最佳答案

关于 CALayer mask 属性的苹果文档:

An optional layer whose alpha channel is used as a mask to select between the layer's background and the result of compositing the layer's contents with its filtered background.

所以你应该修复图像的 alpha channel 。黑色像素应该是不透明的,而白色像素应该是完全透明的。

关于objective-c - 使用 UIImage b/w iOS 屏蔽 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14014422/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com