SORU
18 EKİM 2010, PAZARTESİ


Ne kadar dokunaklı bir MKMapView(İOS) için bir itme pimi eklemek için?

Kullanıcı bir MKMapView dokunmatik bir nokta coordonate almak zorunda kaldım. Interface Builder ile çalışmıyorum. Bana bir örnek veya link verebilir.

Çok teşekkürler

CEVAP
18 EKİM 2010, PAZARTESİ


Bunun için UILongPressGestureRecognizer kullanabilirsiniz. Size veya mapview oluşturmak başlatmak her yerde, ilk ona algılayıcı takın:

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];

Hareketi işleyicisi sonra:

- (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 o MKAnnotation protokol tanımlamak için uygun bir sınıftır. Eğer uygulama sadece iOS 4.0 veya daha sonra çalışan, önceden tanımlanmış MKPointAnnotation sınıfı yerine kullanabilirsiniz.

Kendi MKAnnotation sınıf oluşturma ile ilgili örnekler için, örnek WeatherMap MapCallouts uygulamaları görmek.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • AverageBroTV

    AverageBroTV

    20 Mart 2013
  • Tracy Hairston

    Tracy Hairst

    22 Mayıs 2009
  • WHZGUD2

    WHZGUD2

    21 EYLÜL 2011