0
我正在检测长按以在地图上放置针脚及其工作方式,我添加了一个pinId变量,以增加evry时间我放弃了一个指示以检查只有两个针脚被丢弃相同的地图,但这里有东西不能正常工作我猜,因为我只能在地图上放一个别针!使用长按钮丢弃2个针脚
下面是代码:
-(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;
}
你可以确保你的其他部分被称为你第二次执行长按 – visakh7 2011-03-31 12:04:51