Ответ 1
Для этого вы можете использовать UILongPressGestureRecognizer. Везде, где вы создаете или инициализируете вид карты, сначала присоедините к нему распознаватель:
UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc]
initWithTarget:self action:@selector(handleLongPress:)];
lpgr.minimumPressDuration = 2.0; //user needs to press for 2 seconds
[self.mapView addGestureRecognizer:lpgr];
[lpgr release];
Затем в обработчике жестов:
- (void)handleLongPress:(UIGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer.state != UIGestureRecognizerStateBegan)
return;
CGPoint touchPoint = [gestureRecognizer locationInView:self.mapView];
CLLocationCoordinate2D touchMapCoordinate =
[self.mapView convertPoint:touchPoint toCoordinateFromView:self.mapView];
YourMKAnnotationClass *annot = [[YourMKAnnotationClass alloc] init];
annot.coordinate = touchMapCoordinate;
[self.mapView addAnnotation:annot];
[annot release];
}
YourMKAnnotationClass - это определенный вами класс, соответствующий протоколу MKAnnotation. Если ваше приложение будет работать только на iOS 4.0 или более поздней версии, вы можете использовать предопределенный класс MKPointAnnotation.
Примеры создания собственного класса MKAnnotation см. В примере приложения MapCallouts.