Kunal Shrivastava
Kunal Shrivastava

Reputation: 612

UIImageView not showing on top of MKMapView

In IB, I have added a UIImageView on top of MKMapView(which spans the whole screen above the bottom tab bar). The UIImageView shall represent the map legend.

I have created an IBOutlet for the UIImageView and have synthesized it in the .m file of my mapViewController. I am setting the image programmatically using the following line of code:

[legend setImage:[UIImage imageNamed:@"maplegend.png"]]; 

I want this image to be there all the time at the bottom right corner of the MKMapView.

But no image is being displayed when I run my project.

Please guide.

Upvotes: 1

Views: 330

Answers (1)

Michael
Michael

Reputation: 6517

I once had the same problem. I solved it by putting the views next to each other instead of over each other in the view hierarchy.

The view hierarchy would then look like this

  • containerView (UIView)
    • mapView (MKMapView)
    • myBanner (UIImageView)

(containerView.subviews == @[mapView, myBanner] in this case)

myBanner can still overlap mapView, because views with a higher index will be placed above views with a lower index.

This would not work:

  • containerView (UIView)
    • myBanner (UIImageView)
    • mapView (MKMapView)

I'm not 100% sure, but I think there is a problem with the MKMapView: it just doesn't want you to put subviews on top of it.

If you also want your legend to be click-throughable (i.e. not accepting touch-events), you would have to create your own UIView subclass for the containerView and override the -hitTest:withEvent: method...

Upvotes: 1

Related Questions