我已经创建了一个mapview,它具有一个按钮,可以根据项目需求在“编辑”模式和“拖动”模式之间切换。我意识到,通过在viewForAnnotation中设置可拖动的标签,您的注释可以从创建拖放,但是所需的行为不允许这样做。我尝试了几种不同的方式将注释更改为可拖动但没有成功。首先想到的是循环现有的注释,并设置每一个'可拖动'和'选择',但我得到一个无法识别的选择器发送到实例错误(我尝试实例化一个新的注释传入对象和重绘而在循环,但我得到了同样的错误,以及):启用和禁用注释拖动(即时)(iOS Mapkit)
NSLog(@"Array Size: %@", [NSString stringWithFormat:@"%i", [mapView.annotations count]]);
for(int index = 0; index < [mapView.annotations count]; index++) {
if([[mapView.annotations objectAtIndex:index]isKindOfClass:[locAnno class]]){
NSLog(@"** Location Annotation at Index: %@", [NSString stringWithFormat:@"%i", index]);
NSLog(@"* Location Marker: %@", [mapView.annotations objectAtIndex:index]);
}
if([[mapView.annotations objectAtIndex:index]isKindOfClass:[hydAnno class]]) {
NSLog(@"** Hydrant Annotation at Index: %@", [NSString stringWithFormat:@"%i", index]);
NSLog(@"* Hydrant Marker: %@", [mapView.annotations objectAtIndex:index]);
[[mapView.annotations objectAtIndex:index]setSelected:YES];
[[mapView.annotations objectAtIndex:index]setDraggable:YES];
}
}
的第二个想法是用“didSelectAnnotationView”,并设置选择和拖动时,它的选择注解,并重置属性时模式再次切换回来。这工作,但非常糟糕的事件并不总是火灾和你的左边挖掘注释一次或多次前,将改变的属性:
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {
NSLog(@"Annotation Selected!");
if(!editMode) {
view.selected = YES;
view.draggable = YES;
}
}
第一次尝试似乎是最简单的解决方案,如果我能得到它的工作。另一方面,使用didSelect方法非常麻烦并且非常棘手。我对iOS开发很陌生,所以我很抱歉如果我忽略了一些新手,同时剔除这个问题。我很感谢社区可以提供的任何见解。非常感谢。
谢谢你帮我解决这个问题!我有一种感觉,我试图操纵错误的对象。我需要解决的唯一问题是,当我切换到拖动模式时,我需要在拖动它之前敲击一次注释(而不是立即拖动)。我通过在viewAnnotation中调用setSelected和setDraggable来解决此问题,而不是annotation.selected和annotation.draggable。 – ninehundredt 2012-04-03 15:30:11