Is it possible to mask CALayer in iPhone?

杀马特。学长 韩版系。学妹 提交于 2019-12-11 06:21:48

问题


I'm trying to mask CALayer with a bitmap image. And I failed masking CALayer. My code is:

// 'PreloadViewController layerWithImageNamed' create a layer and set it's contents as specified UIImage.
CALayer* title = [PreloadViewController layerWithImageNamed:@"pinkhug_txt.png"];
 [[[self view] layer] addSublayer:title];

 CALayer* title_mask = [PreloadViewController layerWithImageNamed:@"hug_mask.png"];
 [title setMask:title_mask];

The Apple reference says "CALayer in iPhone does not support mask property". But there is a postings about this on SO. Is it possible? Or what's wrong with my code?


回答1:


It was my fault and resolved now. I used an image without alpha channel. Unlike traditional masking techniques, CALayer uses mask image's alpha channel as mask data.



来源:https://stackoverflow.com/questions/2743169/is-it-possible-to-mask-calayer-in-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!