mmapapviewを使用してアプリケーションを開発しています。これはピンをmapviewに落とします。viewForAnnotationからXCode MKMapViewピンを特定する方法
ピンに関する情報に基づいてピンを色付けできる必要があります。
地図上のアイコンをドロップし、現在のコードは次のとおりです。
customPin.pinColor = MKPinAnnotationColorRed;
その後、私はすべてドロップされたピンの色を変更することができますが、どのようにすることができます:私は、行を変更した場合
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation {
if (annotation == self.mapView.userLocation) return nil;
NSLog(@"annotation = %@", annotation);
static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
MKPinAnnotationView* customPin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier];
customPin.pinColor = MKPinAnnotationColorRed;
customPin.animatesDrop = YES;
customPin.canShowCallout = YES;
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
customPin.rightCalloutAccessoryView = rightButton;
return customPin;
}
どのピンがドロップされているかを識別し、必要に応じてピンの色を変更するだけです。
私は、ログの行を追加:
NSLog(@"annotation = %@", annotation);
をしかし、それは例えば、返されます。
annotation = <MapAnnotation: 0x7feabd749190>
annotation = <MapAnnotation: 0x7feac04edf50>
annotation = <MapAnnotation: 0x7feabd79f860>
は、どのように私はピンを識別するためにこれを使用することができますか?
注釈ピンを別の場所に塗りつぶす必要がありますか?
アノテーションを追加するときにカスタムアノテーションクラスを作成しましたか? –
これを確認してくださいhttps://www.raywenderlich.com/90971/introduction-mapkit-swift-tutorial –