我有一个UIView子类,我想用它来绘制不同混合模式的图像。UIView子类中的drawRect不更新图像
代码:
@implementation CompositeImageView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
-(void)setBlendMode:(CGBlendMode) composite
{
blender = composite;
}
-(void)setImage:(UIImage*) img
{
image = img;
}
- (void)drawRect:(CGRect)rect
{
NSLog(@"it draws");
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextSetBlendMode(c, blender);
CGContextDrawImage(c, rect, image.CGImage);
}
@end
,我用它来设置它,它是代码:
[testImage setImage:[UIImage imageNamed:@"Prayer_Background_Paid"]];
[testImage setBlendMode:kCGBlendModeColor];
[testImage setNeedsDisplay];
我使用界面生成器放置一个大长方形的UIView,然后将其类到CompositeImageView。然而,它仍然是一个巨大的白色方块。即使我注释掉drawRect中的所有内容,它仍会绘制白色方块。但是,它调用drawRect,因为“正在绘制”正在被记录。
你确定你的图片不是'nil'(可能是文件名中的拼写错误)吗? – omz 2012-04-28 03:30:19
是的。我还尝试了一些项目中的其他图像。除非我得到/绘制图像的方式有什么问题,否则我不知道什么可能是错的 - 因此我在这里发布。 (不知道什么与反对票) – Nyth 2012-05-07 16:20:26
你能够使这项工作?我现在正在尝试做同样的事情。 – 2014-07-27 11:31:53