English 中文(简体)
Is there a way to subclass the MKAnnotationView used for the MKUserLocation blue dot?
原标题:

I ve created a custom annotation view by subclassing MKAnnotationView. This class also creates a custom callout (info pop-up bubble ) view which is skinned to match my app.

I also want to be able to reskin the callout bubble for the user location dot, but it seems as though the only control I have over that view is whether it is overridden completely or not, by using the following inside the mapView:viewForAnnotation: method:

if(annotation == self.mapView.userLocation)
{
    return nil;
}

But what I really want to do is find out what annotation view MapKit is using for the user location blue dot, and then subclass it so I can skin its callout bubble... Or is there another way? Or just no way at all?

问题回答

I am not sure this will help you, but you can use the default user location annotation view, then steal the view in mapView:didSelectAnnotationView::

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
    if (view == [mapView viewForAnnotation:mapView.userLocation]) {
        // do what you want to  view 
        // ...
    }
    // ...
}

I have used this trick to change the callout title and subtitle, and add an image using leftCalloutAccessoryView. However, I haven t tried totally replacing the callout, so I don t know if it s possible.

You can use

if ([annotation isKindOfClass:[MKUserLocation class]]) { // or if(annotation == self.mapView.userLocation)
   MKAnnotationView * annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"MyLocation"];
   if (annotationView == nil) {
      annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"MyLocation"] autorelease];
         annotationView.canShowCallout = NO;
         annotationView.image = [UIImage imageNamedWithBrand:@"MyLocationPin.png"];
      } else {
         annotationView.annotation = annotation;
      }
   return annotationView;
}

I think it is not possible directly, but you can override some methods in runtime with this: http://theocacao.com/document.page/266





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签