关于MKAnnotation的循环利用和一开始显示标注的问题

  • 为MKAnnotation的coordinate赋值后,设置[self.mapView selectAnnotation:self.annotation animated:YES]; 才能显示标注
// 长按选中地址
- (void)longPress:(UILongPressGestureRecognizer *)longPress
{
    if (longPress.state == UIGestureRecognizerStateBegan)
    {
        CGPoint point = [longPress locationInView:self.mapView];
        // 将点击位置转换为经纬度
        CLLocationCoordinate2D coordinate = [self.mapView convertPoint:point toCoordinateFromView:self.mapView];
        // 取消选中(如果不取消选中,标注显示的还是之前的地址)
        [self.mapView deselectAnnotation:self.annotation animated:YES];
        //设置大头针的经纬度
        self.annotation.coordinate = coordinate;
        // 要在设置大头针的coordinate后设置为选中才可以显示标注
        [self.mapView selectAnnotation:self.annotation animated:YES];
        }
    }
}

你可能感兴趣的:(iOS控件,ios地图定位)