Ste*_*e N 6 iphone quartz-graphics drawrect mkmapview mkannotation
我已经将MKAnnotationView子类化,以创建一个注释,该注释基本上通过覆盖drawRect在地图视图上的点周围绘制一个圆.在以下情况下(在模拟器中)圆圈绘制正常:
发生以下任何操作时,圆圈将消失:
如果"工作"组中的任何操作在消失后进行,则该圆圈将重新出现.
什么可能导致这个?我不是抽奖/展示/布局专家(坦率地说,我也不是对象C或iPhone专家).
这是一些稍微简化的代码,它似乎与我的MKAnnotationView子类最相关:
- (void)drawRect:(CGRect)rect {
// Drawing code
[self drawCircleAtPoint:CGPointMake(0,0) withRadius:self.radiusInPixels andColor:self.circleAnnotation.color];
}
- (void)drawCircleAtPoint:(CGPoint)p withRadius:(int)r {
CGContextRef contextRef = UIGraphicsGetCurrentContext();
float alpha = 0.75;
CGContextSetRGBFillColor(contextRef, 255, 0, 0, alpha);
CGContextSetRGBStrokeColor(contextRef, 255, 0, 0, alpha);
// Draw a circle (border only)
CGContextStrokeEllipseInRect(contextRef, CGRectMake(0, 0, 2*r, 2*r));
}
Run Code Online (Sandbox Code Playgroud)
你添加这个方法了吗?
- (void)setAnnotation:(id <MKAnnotation>)annotation
{
[super setAnnotation:annotation];
[self setNeedsDisplay];
}
Run Code Online (Sandbox Code Playgroud)
这取自 Apple 的名为 WeatherMap 的示例代码应用程序,该应用程序已从 Apple 开发人员中心删除,但可以在 github 上找到 https://github.com/acekiller/iOS-Samples/blob/master/WeatherMap/Classes/WeatherAnnotationView.m
| 归档时间: |
|
| 查看次数: |
1649 次 |
| 最近记录: |