How can I overlay a search bar over MapKit?

2019-07-24 11:32发布

问题:

How can I overlay a search bar over MapKit?

I like how the new Google Maps application has a search box and buttons that hover over the map.

See the image on the left:

I'm not sure how to get this however as I have not been programming iOS for longer than a couple of weeks. Any ideas on how I could hover UI elements on top of each other with Storyboards/Objective-C?

Presumably it's a navigation bar that has been made invisible but how is this done, and how is it the Map appears underneath it?

回答1:

The search box appears to be a custom control which mimics behavior of a UISearchBar and which would inherit from UIControl. Since UIControl inherits from UIView, you can add it to your map view

  1. programatically with the addSubview: method
  2. via Storyboard by adding your custom control to your map in the appropriate view controller