tennis779
tennis779

Reputation: 348

Trouble creating MapView and UISearchBar together, map overtakes screen

I am creating a mapView that zooms into the user's location. I want the to have a search bar at the top so the user can search for various things.

I am having trouble adding a search bar into my ViewController. The map covers the entire screen every time. I believe it is because of this code.

Is there another way to initialize the map without using self.view.bounds? I don't want to use a manual CGRectMake cause it doesn't work for all versions of the iPhone.

Please help I have been stuck for hours.

self.myMapView =[[MKMapView alloc]initWithFrame:self.view.bounds];


self.myMapView.delegate=self;

//Set a standard mapview, Enable scrolling and zooming
self.myMapView.mapType = MKMapTypeStandard;
self.myMapView.scrollEnabled = YES;
self.myMapView.zoomEnabled = YES;
//specifcy resizing
self.myMapView.autoresizingMask = UIViewAutoresizingFlexibleWidth |    UIViewAutoresizingFlexibleHeight;

Upvotes: 0

Views: 61

Answers (1)

Enrico Susatyo
Enrico Susatyo

Reputation: 19800

You should use Auto Layout. Add constraints to your map view so that the distance with top layout guide, left, right, and bottom layout guide are 0.

Upvotes: 1

Related Questions