Reputation: 1526
Now since they're no more views in MKOverlayView, and it's called MKOverlayRenderer, how could I add an UIImageView to my MKMapView? Note: I know how to add an image onto the map by drawing it onto a CGContextRef, but I specifically require UIImageView to be added. Thanks!
Upvotes: 3
Views: 1313
Reputation: 727
Here is how to add UIImage. If you like to add UIImageView then the Apple documentation states (Apple Doc MKOverlayRenderer):
It is recommended that you use Core Graphics to draw any content for your overlays. If you choose to draw using UIKit classes and methods instead, you must push the specified graphics context onto the context stack (using the UIGraphicsPushContext function) before making any drawing calls. When you are done drawing, you must similarly pop the graphics context off the stack using the UIGraphicsPopContext. Overlay drawing typically occurs on background threads to improve performance, so do not manipulate UIKit views or other objects that can only be manipulated on the app’s main thread.
#import <Foundation/Foundation.h>
@import MapKit;
@interface MyOverlayRenderer : MKOverlayRenderer
@end
And the implementation
#import "MyOverlayRenderer.h"
@implementation MyOverlayRenderer
- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context {
UIImage *image = [UIImage imageNamed:@"indigo_eiffel_blog.png"];
CGImageRef imageReference = image.CGImage;
MKMapRect theMapRect = [self.overlay boundingMapRect];
CGRect theRect = [self rectForMapRect:theMapRect];
CGContextScaleCTM(context, 1.0, -1.0);
CGContextTranslateCTM(context, 0.0, -theRect.size.height);
CGContextDrawImage(context, theRect, imageReference);
}
@end
Upvotes: 2
Reputation: 5128
If you're using a view, you should probably be adding a subview to MKAnnotationView
.
Upvotes: -1