我需要重画我的自定义MKAnnotationView,这取决于MKMapView的缩放级别。据我所知,我必须在map控制器的下一个方法中这样做。
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated在这里删除并向MKMapView添加注释会强制闪烁AnnotationView。我怎样才能以正确的方式做到这一点呢?
发布于 2011-04-22 04:09:43
您不需要删除它,然后再重新添加它。只需对自定义注释视图进行更改并调用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];的重绘。您可以对图像执行相同的操作。
https://stackoverflow.com/questions/5587087
复制相似问题