MKPinAnnotationView
iPhone でドラッグ機能を実装するための良いチュートリアルを提案できる人はいMKMapView
ますか?
2653 次
2 に答える
3
注釈をドラッグ可能にするには、注釈ビューのドラッグ可能プロパティを YES に設定します。
これは通常、viewForAnnotation デリゲート メソッドで行われるため、.h ファイルでMKMapView
デリゲートを設定し、それに準拠していることを確認してください。self
例えば:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
static NSString *reuseId = @"pin";
MKPinAnnotationView *pav = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseId];
if (pav == nil)
{
pav = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseId];
pav.draggable = YES; // Right here baby!
pav.canShowCallout = YES;
}
else
{
pav.annotation = annotation;
}
return pav;
}
では、注釈のドラッグ アクションを管理するコードを次に示します。
- (void)mapView:(MKMapView *)mapView
annotationView:(MKAnnotationView *)annotationView
didChangeDragState:(MKAnnotationViewDragState)newState
fromOldState:(MKAnnotationViewDragState)oldState
{
if (newState == MKAnnotationViewDragStateEnding) // you can check out some more states by looking at the docs
{
CLLocationCoordinate2D droppedAt = annotationView.annotation.coordinate;
NSLog(@"dropped at %f,%f", droppedAt.latitude, droppedAt.longitude);
}
}
これは役立つはずです!
于 2012-12-24T05:15:27.223 に答える