4

我有一个 MapView,上面有两个引脚(自定义引脚)。

两个引脚都设置为可拖动,但我的问题是在我可以拖动其中一个之前,我首先必须选择它,然后才能开始拖动它。这意味着在屏幕上点击两次。

我知道这个答案,但他的地图上只有一个图钉,在我看来,一次只能选择一个图钉,因此设置 [MyPin setSelected:YES]; 在这种情况下不会帮助我。

谢谢您的帮助!

//Custom pin on mapview
-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {

            MKAnnotationView *MyPin=[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"current"];

             MyPin.draggable = YES;

            //Get annotaion title to determine what image to use
            MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc]init];
            annotationPoint = annotation;

            if([annotationPoint.title isEqualToString:@"user"])
            {
                MyPin.image = [UIImage imageNamed:@"userLocation_pin"];
                MyPin.centerOffset = CGPointMake(-13, -5); //Offset custom image to display at the exact pin point GPointMake([left/right], [up/down]);
            }
            else if ([annotationPoint.title isEqualToString:@"destination"])
            {
                MyPin.image = [UIImage imageNamed:@"destination_pin_up"];
                MyPin.centerOffset = CGPointMake(-13, -5); //Offset custom image to display at the exact pin point GPointMake([left/right], [up/down]);
            }

            return MyPin;
        }
4

1 回答 1

1

通过添加 [MyPin setSelected:YES] 设法解决了我自己的问题;在这样的 if 语句中:

//Custom pin on mapview
-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {

            MKAnnotationView *MyPin=[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"current"];

             MyPin.draggable = YES;

            //Get annotaion title to determine what image to use
            MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc]init];
            annotationPoint = annotation;

            if([annotationPoint.title isEqualToString:@"user"])
            {
                MyPin.image = [UIImage imageNamed:@"userLocation_pin"];
                MyPin.centerOffset = CGPointMake(-13, -5); //Offset custom image to display at the exact pin point GPointMake([left/right], [up/down]);
                [MyPin setSelected:YES];
            }
            else if ([annotationPoint.title isEqualToString:@"destination"])
            {
                MyPin.image = [UIImage imageNamed:@"destination_pin_up"];
                MyPin.centerOffset = CGPointMake(-13, -5); //Offset custom image to display at the exact pin point GPointMake([left/right], [up/down]);
                [MyPin setSelected:YES];
            }

            return MyPin;
        }
于 2013-06-26T12:48:35.843 回答