开发者

Dropping 2 pins with long tap

I'm detecting a long tap to put a pin on the map and its working, I add a pinId variable that i increment evry time i drop a poin to check that only two pins are dropped in the same map but here something is not working fine i guess because i can only put one pin on the map!

Here is the code:

-(void)handleLongPressGesture:(UIGestureRecognizer*)sender {

if (sender.state == UIGestureRecognizerStateEnded)

{

  [self.mapView removeGestureRecognizer:sender];

}else{ 
    if (pinId < 3) {


        CGPoint point = [sender locationInView:self.mapView];

        CLLocationCoordinate2D locCoord = [self.mapView convertPoint:point toCoordinateFromView:self.mapView];


        MapAppAnnotation* annotation = [[MapAppAnnotation alloc]initWithCoordinate:locCoord andID:pinId];
        pinId++;
        [mapView addAnnotation:annotation];
        [annotation release];

    }}
}

- (void)update{


UI开发者_JAVA技巧LongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressGesture:)];

[self.mapView addGestureRecognizer:longPressGesture];


[longPressGesture release];

}

- (void)viewDidLoad {

[super viewDidLoad];
//...

pinId = 1;

 self.update;
}


At a guess; it's because removeGestureRecognizer is being called after the first long press. Does it work if you remove that call?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜