annotationView覆盖drawRect,带有alpha的图像

时间:2012-02-10 10:05:04

标签: iphone objective-c ios core-graphics

您好我想在我的自定义annotationView中覆盖drawrect,所以当我写

[[_mapView viewForAnnotation:annotation] setNeedsDisplay]; 

我的注释视图将被重绘,我不必删除注释并再次添加。

这是我的drawRect

- (void)drawRect:(CGRect)rect {
    UIImage* theImage = nil;
    if( _pinType == T_UNKNOWN ) theImage = [UIImage imageNamed:@"imgU.png"];
    else theImage = [UIImage imageNamed:@"imgK.png"];
    [theImage drawInRect:rect];
}

问题是我的图像是alpha,alpha部分是黑色。

所以也许有人知道这个解决方案或一些建议吗? 我已经阅读了很多关于此的帖子,也使用了核心图形,但没有找到解决方案..

提前致谢!

2 个答案:

答案 0 :(得分:3)

您希望此视图部分透明并在其下显示内容吗?如果是,请使用[self setOpaque:NO]。不透明视图的drawRect负责使用完全不透明的颜色绘制矩形中的每个像素。

答案 1 :(得分:1)

此功能适用于iOS 5.0。当你使用iOS版本< 5.0,你将alpha部分视为黑色。

尝试使用其他方法绘制图像。我不知道你使用这个代码。尝试使用:

UIImageView *image = [[UIImageView alloc] initWithImage: theImage];
image.opaque = NO;
[self.view addSubview: image];
相关问题