Subclasses of MKAnnotationView

I was wondering if anyone knows of any subclasses for the MKAnnotationView class. In the apple documentation, they say one example is MKPinAnnotationView, so I was wondering if there were other pre-created subclasses, for example, used to track the current location of devices. If anyone has any tips on creating my own subclass of the MKAnnotationView class, which would also be great.

Thanks bubster

+5
source share
2 answers

I do not know any other templates, but this does not mean that they do not exist. :)

, : , MKAnnotation. NSString* title subtitle CLLocationCoordinate2D setter (, ). . mapView -mapView:viewForAnnotation: , UITableView. , View , (, UIButtonTypeDetailDisclosure ). . image MKAnnotationView. , : aView.centerOffset = CGPointMake(0, -20)

:

- (MKAnnotationView *) mapView: (MKMapView *) mapView viewForAnnotation: (id<MKAnnotation>) annotation {
    // reuse a view, if one exists
    MKAnnotationView *aView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"pinView"];

    // create a new view else
    if (!aView) {
        aView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pinView"];
    }

    // now configure the view
    aView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [(UIButton*)aView.rightCalloutAccessoryView addTarget:self action:@selector(showDetails:) forControlEvents:UIControlEventTouchUpInside];
    aView.canShowCallout = YES;
    aView.enabled = YES;
    aView.image = [UIImage imageNamed:@"green_pin.png"];
    aView.centerOffset = CGPointMake(0, -20);

    return aView;
}
+7

, - :

Objective-C, : http://cocoawithlove.com/2010/01/getting-subclasses-of-objective-c-class.html

, MKAnnotationView, :

MKTransitCalloutView, MKAdAnnotationView, MKUserLocationView, MKUserLocationBreadCrumbView MKPinAnnotationView

MKPinAnnotationView . - , Apple .

+9

All Articles