iPad и MapKit - невозможно перетащить маркер - PullRequest
0 голосов
/ 30 марта 2012

У меня крошечный крестик, здесь.

Насколько я знаю, я все делаю правильно.

Я делаю то, что написано в этой публикации , но без игры в кости.

Основная проблема заключается в том, что перетаскиваемый маркер не будет перетаскиваться.

Вот проблемное место. Я хочу специализировать простой черный маркер (базовый класс - не перетаскиваемый черный маркер) для перетаскивания.

Вот его интерфейс:

/**************************************************************//**
 \class BMLT_Search_BlackAnnotationView
 \brief We modify the black annotation view to allow dragging.
 *****************************************************************/
@interface BMLT_Search_BlackAnnotationView : BMLT_Results_BlackAnnotationView

@property (nonatomic,readwrite,assign) CLLocationCoordinate2D   coordinate;

- (id)initWithAnnotation:(id<MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier coordinate:(CLLocationCoordinate2D)inCoordinate;
@end

А вот и его реализация:

/**************************************************************//**
 \class BMLT_Search_BlackAnnotationView
 \brief We modify the black annotation view to allow dragging.
 *****************************************************************/
@implementation BMLT_Search_BlackAnnotationView
@synthesize coordinate;

/**************************************************************//**
 \brief We simply switch on the draggable bit, here.
 \returns self
 *****************************************************************/
- (id)initWithAnnotation:(id<MKAnnotation>)annotation
         reuseIdentifier:(NSString *)reuseIdentifier
              coordinate:(CLLocationCoordinate2D)inCoordinate
{
    self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];

    if ( self )
        {
        [self setDraggable:YES];
        [self setCoordinate:inCoordinate];
        }

    return self;
}

/**************************************************************//**
 \brief Handles dragging.
 *****************************************************************/
- (void)setDragState:(MKAnnotationViewDragState)newDragState
            animated:(BOOL)animated
{
#ifdef DEBUG
    NSLog(@"BMLT_Search_BlackAnnotationView setDragState called with a drag state of %@.", newDragState);
#endif
    self.dragState = newDragState;
}

@end

setDragState: animated: никогда не вызывается.

Насколько я знаю, я все делаю правильно.

Очевидно, что нет.

Есть идеи?

Вот настройки и обратный вызов:

/**************************************************************//**
 \brief  If this is an iPad, we'll set up the map.
 *****************************************************************/
- (void)setUpMap
{
    if ( mapSearchView )    // This will be set in the storyboard.
        {
#ifdef DEBUG
        NSLog(@"A_BMLT_SearchViewController setUpIpadMap called (We're an iPad, baby!).");
#endif
        BMLTAppDelegate *myAppDelegate = [BMLTAppDelegate getBMLTAppDelegate];  // Get the app delegate SINGLETON

        CLLocationCoordinate2D  center;
#ifdef DEBUG
        NSLog(@"A_BMLT_SearchViewController setUpIpadMap We're using the canned coordinates.");
#endif
        center.latitude = [NSLocalizedString(@"INITIAL-MAP-LAT", nil) doubleValue];
        center.longitude = [NSLocalizedString(@"INITIAL-MAP-LONG", nil) doubleValue];

        if ( [myAppDelegate myLocation] )
            {
#ifdef DEBUG
            NSLog(@"A_BMLT_SearchViewController setUpIpadMap We know where we are, so we'll set the map to that.");
#endif
            center = [myAppDelegate myLocation].coordinate;
            }

        MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(center, 25000, 25000);

        [mapSearchView setRegion:region animated:NO];

        BMLT_Results_MapPointAnnotation *myMarker = [[BMLT_Results_MapPointAnnotation alloc] initWithCoordinate:center andMeetings:nil];

        [myMarker setTitle:@"Marker"];

        [mapSearchView addAnnotation:myMarker];

        if ( [[BMLT_Prefs getBMLT_Prefs] keepUpdatingLocation] )    // If the user wants us to keep track of them, then we'll do so.
            {
            [mapSearchView setUserTrackingMode:MKUserTrackingModeFollow animated:YES];
            }
        else
            {
            [mapSearchView setUserTrackingMode:MKUserTrackingModeNone animated:NO];
            }
        }
}

#pragma mark - MkMapAnnotationDelegate Functions -

/**************************************************************//**
 \brief Returns the view for the marker in the center of the map.
 \returns an annotation view, representing the marker.
 *****************************************************************/
- (MKAnnotationView *)mapView:(MKMapView *)mapView
            viewForAnnotation:(id < MKAnnotation >)annotation
{
#ifdef DEBUG
    NSLog(@"A_BMLT_SearchViewController viewForAnnotation called.");
#endif
    static NSString* identifier = @"single_meeting_annotation";

    MKAnnotationView* ret = [mapView dequeueReusableAnnotationViewWithIdentifier:identifier];

    if ( !ret )
        {
        ret = [[BMLT_Search_BlackAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier coordinate:[annotation coordinate]];
        }

    return ret;
}

Ответы [ 2 ]

1 голос
/ 30 марта 2012

Вам необходимо настроить перетаскивание вида anootation.

[ret setDraggable:YES]
0 голосов
/ 01 апреля 2012

Просто хотел сообщить о РЕАЛЬНОЙ проблеме здесь:

PEBCAK

Проблема в том, что цель перетаскивания на иконке крошечная. С симулятором манипулятор (курсор) также крошечный, так что это может быть проблемой выстроить их в ряд.

Лучше на устройстве, с моим пальцем, хотя это тоже дергается.

Кстати: код карты сейчас отличается от приведенного выше. Я исправил несколько других проблем.

Если кто-то хочет увидеть код, весь проект с открытым исходным кодом ( GitHub - посмотрите BMLT IOS ). В настоящее время я работаю в ветке 2.0 и буду некоторое время, так что это движущаяся цель.

...