objective-c - 使用 UIImage 黑白 iOS 屏蔽 UIView

标签 objective-c ios ipad uiview uiimage

我正在为 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 属性的 Apple 文档:

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 黑白 iOS 屏蔽 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14014422/

相关文章:

cocoa - 应用开发: Cocoa vs Sencha vs Others

ios:如何使用 StoryBoards 从 ViewController 打开 Tab Bar Controller

objective-c - 更改 UIPickerView 行高

ios - 警报 View :(UIAlertView *) alertView method not working in Appdelegate

objective-c - 在 UIScrollview 中放置 View

iOS Swift 内存错误,在模拟器上不会发生?

ios - 如何让我的应用程序在 iPhone 4 和 iPhone 5 屏幕上运行?

ios - 分组 UITableview 中减少单元格

ios - 应用程序图标显示在移动应用程序上的启动屏幕图像之前

iphone - 如何在 iOS 中获取时区列表,就像我们在注册 Web 应用程序时获取的一样