iphone - 重绘MKAnnotationView

标签 iphone mkmapview mkannotationview

取决于 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/

相关文章:

iphone - 如何确定 UITableView 何时完成加载所有行?

iphone - 缩放以适合所有注释的区域 - 最终在注释之间放大

ios - 我想在应用程序找到用户位置时收到信号。

ios - MKMapView 中的箭头图标

ios - 为什么我的 map View 标注是半透明/透明的,我该如何更改它的颜色?

ios - 在 iOS 上检测 WiFi 启用/禁用的更好方法?

iphone - UITableView 的 didSelectRowAtIndexPath 仅每隔一段时间调用一次

iphone - 如何更改 MFMailViewController 消息正文中的样板 "Sent from my iPhone"文本?

ios - 基于点击坐标的MKpolygon

swift - MKAnnotationView 缩放图像导致 calloutView 也缩放