Google Maps iOS SDK - Add UIView/UIButton over a GMSMapView

…衆ロ難τιáo~ 提交于 2019-12-17 19:27:27

问题


I'm developing an iOS app with Google Maps iOS SDK with storyboard. On my main view controller in "viewDidLoad" I have implemented a GMSMapView and shows it by

self.view = mapView_;

and everything goes fine. Now I want to add a UIView or UIButton over the map, like myLocation button style. There is any solution to add it and use it via storyboard? I've overlayed objects on the map by code but i really need autolayout so manage it via Storyboard would be nice. Thanks.


回答1:


Try this (making sure you set the mapView frame to a value different than CGRectZero (which works for self.view=mapView only)):

mapView = [GMSMapView mapWithFrame:self.view.bounds camera:camera];
[self.view insertSubview:mapView atIndex:0];

As Saxon said, inserting the view at index 0 will set the rest of the objects in front.




回答2:


Actually, this is the only way that worked for me after trying everything out there

[self.view insertSubview:self.yourUIImageview aboveSubview:self.mapView]

Good luck




回答3:


Do you want to have a location button with your own custom image? or what? Have you tried with: mapview_.settings.myLocationButton = YES; Can you be a little more specific with what you want? I'm also using GM SDK for iOS, so maybe I can help you.




回答4:


You could try something like this:

[self.view insertSubview: mapView_ atIndex: 0];

This will insert the map as a subview of the root view (instead of replacing the root view), leaving your other views (ie buttons etc) in place. Inserting it at index 0 will put it underneath the other views.




回答5:


Add your map as a subview

 GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:coordinate.latitude longitude:coordinate.longitudeoom:6];

mapView = [GMSMapView mapWithFrame:self.view.bounds camera:camera];[self.view insertSubview:mapView atIndex:0];

Now you can drag and drop your whatever your UIcontrol like button , textfield it will visible over the mapview or you can also add as subview like above.



来源:https://stackoverflow.com/questions/16497648/google-maps-ios-sdk-add-uiview-uibutton-over-a-gmsmapview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!