我有这个代码:
-(void)handleLongPressGesture:(UIGestureRecognizer*)sender {
NSNumber* existingpoints = [[NSNumber alloc]init];
existingpoints =[NSNumber numberWithInt:0];
// This is important if you only want to receive one tap and hold event
if (sender.state == UIGestureRecognizerStateEnded)
{
[self.mapView removeGestureRecognizer:sender];
}
else {
do {
int z = 1;
existingpoints =[NSNumber numberWithInt:z];
// Here we get the CGPoint for the touch and convert it to latitude and longitude coordinates to display on the map
CGPoint point = [sender locationInView:self.mapView];
CLLocationCoordinate2D locCoord = [self.mapView convertPoint:point toCoordinateFromView:self.mapView];
// Then all you have to do is create the annotation and add it to the map
MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init]; annotationPoint.coordinate = locCoord;
NSString *latitude = [[NSString alloc] initWithFormat:@"%f",locCoord.latitude];
NSString *longitude = [[NSString alloc] initWithFormat:@"%f", locCoord.longitude];
annotationPoint.title = @"Event";
annotationPoint.subtitle = [NSString stringWithFormat:@"%@ & %@", latitude, longitude];
[mapView addAnnotation:annotationPoint];
[[NSUserDefaults standardUserDefaults]setObject:latitude forKey:@"FolderLatitude"];
[[NSUserDefaults standardUserDefaults]setObject:longitude forKey:@"FolderLongitude"];
} while ([existingpoints intValue] == 0);
}
}
...但问题是,当我按住时,然后拖动不止一个针脚。我只想添加一个引脚。所以我尝试了do方法,但它不起作用。我无法理解,因为当我执行代码时,我将 NSNumber 的值变为 1,而 while 说 = 0 来运行代码。
请帮忙!!