我正在尝试在 iPhone 上使用核心图像。我可以使用石英合成颜色来绘制 uiview,但我想将每个组件分成CALayer
(UIview消耗较多资源)。
所以我有一个白色蒙版,我想用它来过滤背景位图,并且我想尝试不同的混合模式。不幸的是,这些图层只是“添加”它们的颜色。
这是我的代码:
@implementation WhiteLayerHelper
- (void)drawLayer:(CALayer *)theLayer
inContext:(CGContextRef)myContext
{
// draw a white overlay, with special blending and alpha values, so that the saturation can be animated
CGContextSetBlendMode(myContext,kCGBlendModeSaturation);
CGContextSetRGBFillColor(myContext,1.0,1.0,1.0,0.9);
CGContextFillRect(myContext,[UIScreen mainScreen].bounds);
}
@end
这是主要视图drawrect
代码,我在其中使用我的 CALayer:
- (void)drawRect:(CGRect)rect {
//get the drawing context
CGContextRef myContext = UIGraphicsGetCurrentContext();
// draw the background
[self fillContext:myContext withBounds:m_overlayRect withImage:m_currentImage];
[whiteLayer renderInContext:myContext];
}
有什么不对?
我设法通过将多个 CALayer 直接绘制到 UIView 的图形上下文中来获得合成多个 CALayer 的效果。
-(void)drawRect:(CGRect)rect {
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextSetBlendMode(c, kCGBlendModeDifference);
[myLayer drawInContext:c];
}
顺便说一句,我没有将图层添加为视图图层的子图层(也就是说,我从未调用过 [myView.layer addSublayer:myLayer])
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)