我的地图图钉可以非常密集地填充,因此当选择一个图钉时,标注会弹出,但大部分被所有其他地图图钉遮挡 - 我可以将地图图钉放在前面,它有一个代表选定的地图图钉(不是点击标注,选择引脚)。
有什么解决方法的建议吗?
如果您使用自定义注释视图,您可以为选定的属性添加一个观察者,该观察者在选择引脚时充当委托。
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
MKAnnotation *annview = ...code to either dequeue or create new object...
[annview addObserver:self forKeyPath:@"selected" options:NSKeyValueObservingOptionNew context:@"selectedmapannotation"];
return annview;
}
然后你可以监视所选状态
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context;
Mugunth Kumar 链接的答案也将为您提供所需的结果,只是您在问题中提到了类似委托的功能。
EDIT:
以下是observeValueForKeyPath:ofObject:change:context:方法的内容示例
NSString *action = (NSString*)context;
if([action isEqualToString:@"selectedmapannotation"]){
BOOL annotationAppeared = [[change valueForKey:@"new"] boolValue];
MKAnnotationView *ann = (MKAnnotationView *)object;
if (annotationAppeared) {
// do something with the annotation when it is selected
}
else {
// do something with the annotation when it is de-selected
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)