How to move a MKAnnotation without adding/removing it from the map?

前端 未结 11 1183
情深已故
情深已故 2020-12-13 06:22

Is it possible to move the coordinate of a MKAnnotation without adding and removing the annotation from the map?

11条回答
  •  没有蜡笔的小新
    2020-12-13 06:59

    Just use KVO:

    [annotation willChangeValueForKey:@"coordinate"];
    [annotation didChangeValueForKey:@"coordinate"];
    

    If your MKAnnotation has an setCoordinate method, just include these lines right there:

    - (void)setCoordinate:(CLLocationCoordinate2D)newCoordinate {
        [self willChangeValueForKey:@"coordinate"];
        coordinate = newCoordinate;
        [self didChangeValueForKey:@"coordinate"];
    }
    

提交回复
热议问题