我已经设法在自定义彩色圆圈注释中绘制数字(基于this)。我想对自定义注记类进行一些优化,然后阅读关于重用的内容。 我的问题是,如果我让东西可重用,注释视图混合在地图上,这是一个大问题。 自定义绘制的注释视图不能重复使用?或者它与视图的注释有什么关系?我的意思是,注释存储要在其视图上绘制的数字,实际上它是注释与其视图之间的1to1关系。重复使用自定义绘制的注释视图
这里是我的相关代码: 定制annotationview的init:
-(id)initWithAnnotation:(id<MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier imageType:(int)imageType {
self = [super initWithAnnotation: annotation reuseIdentifier: reuseIdentifier];
if (self != nil)
{
if ([annotation isKindOfClass:[CircleMarker class]])
{
// custom annotation class with some extra fields
CircleMarker * clm = (CircleMarker *)annotation;
self.locationMarker = clm;
// ... setting frame and other stuff
self.image = [self getImage]; /* this method DRAWS image based on clm */
self.canShowCallout = NO;
}
...
}
和委托:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
static NSString *reuseId_small = @"smallcircle";
static NSString *reuseId_big = @"bigcircle";
CircleAnnotationView * nca = nil;
if ((int)[self.mapView getZoomLevel] < ZOOM_LEVEL_FOR_NUMBERS)
{
nca = (CircleAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:reuseId_small];
if (nca == nil)
nca = [[[CircleAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseId_small imageType:2] autorelease];
}
else
{
nca = (CircleAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:reuseId_big];
if (nca == nil)
nca = [[[CircleAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseId_big imageType:1] autorelease];
}
return nca;
}
我试过用自定义drawRect
功能,以取代self.image =
一部分,但结果是一样的。
谢谢。
或者里面,在这些情况下,只有彩色圆圈(圆圈的背景),可重复使用,我应该绘制的数量从背景中分离出来? – Templar 2012-02-29 08:37:39