取决于 MKMapView 的缩放级别,我需要重新绘制自定义 MKAnnotationView。到目前为止,据我了解,我必须在 map Controller 的下一个方法中执行此操作
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
在此处删除注释然后向 MKMapView 添加注释会强制 AnnotationView 闪烁。 我怎样才能以正确的方式做到这一点?
最佳答案
您不需要删除它然后将其添加回来。只需对自定义注释 View 进行更改并调用 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 的引用,设置不同的徽章编号,并调用 [myView setNeedsDisplay];
请求重绘。您可以对图像执行相同的操作。
关于iphone - 重绘MKAnnotationView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5587087/