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

  • David Wills

    David Wills

    31 Aralık 2007
  • LG Mobile Global

    LG Mobile Gl

    2 EYLÜL 2010
  • Yanko Kral

    Yanko Kral

    8 HAZİRAN 2006