2

取决于 MKMapView 的缩放级别,我需要重绘我的自定义 MKAnnotationView。据我了解,我必须在地图控制器的下一个方法中执行此操作

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated

在此处删除然后向 MKMapView 添加注释会强制 AnnotationView 闪烁。我怎样才能以正确的方式做到这一点?

4

1 回答 1

3

您无需将其删除并重新添加。只需对自定义注释视图进行更改并调用setNeedsDisplay. 例子:

@interface AnnotationClusterView : MKAnnotationView {
@property (nonatomic, assign) int badgeNumber;
}
@implementation AnnotationClusterView
@synthesize badgeNumber;
// ...
- (void)drawRect:(CGRect)rect {
    NSString *string = [NSString stringWithFormat:@"%d",self.badgeNumber];
    [string drawInRect:stringRect withFont:[UIFont fontWithName:@"Helvetica-Bold" size:13.0]];
}
@end

当缩放变化时,获取对 MKAnnotationView 的引用,设置不同的 badgeNumber,并请求重绘调用[myView setNeedsDisplay];。您可以对图像执行相同的操作。

于 2011-04-21T20:09:42.963 回答