我正在检测长按以在地图上放置一个引脚并且它正在工作,我添加了一个pinId变量,我逐渐增加时间,我放下一个指针,检查在同一个地图中只有两个引脚被丢弃但是这里有什么东西因为我只能在地图上放一个图钉,所以工作不正常!
以下是代码:
-(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{
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressGesture:)];
[self.mapView addGestureRecognizer:longPressGesture];
[longPressGesture release];
}
- (void)viewDidLoad {
[super viewDidLoad];
//...
pinId = 1;
self.update;
}
答案 0 :(得分:1)
猜测;这是因为removeGestureRecognizer
是在第一次长按后被调用的。如果你删除那个电话会有效吗?