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