Google Maps iOS SDK – 通过GMSMapView添加UIView / UIButton
我正在用故事板开发带有Google Maps iOS SDK的iOS应用程序。 在我的主视图控制器“viewDidLoad”我已经实现了一个GMSMapView并显示它
self.view = mapView_;
和一切顺利。 现在我想在地图上添加一个UIView或者UIButton,比如myLocationbutton样式。 有任何解决scheme添加并通过故事板使用它? 我用代码覆盖了地图上的对象,但我真的需要自动布局,所以通过故事板pipe理它会很好。 谢谢。
试试这个(确保你设置的mapView框架的值不同于CGRectZero(它适用于self.view = mapView)):
mapView = [GMSMapView mapWithFrame:self.view.bounds camera:camera]; [self.view insertSubview:mapView atIndex:0];
正如撒克逊所说的那样,在索引0处插入视图会将其余的对象设置在前面。
其实这是在尝试了所有东西之后为我工作的唯一方法
[self.view insertSubview:self.yourUIImageview aboveSubview:self.mapView]
祝你好运
你想有一个自定义图像的位置button? 或者是什么? 你有没有尝试过: mapview_.settings.myLocationButton = YES;
你可以更具体一点你想要什么? 我也使用iOS的GM SDK,所以也许我可以帮你。
你可以尝试这样的事情:
[self.view insertSubview: mapView_ atIndex: 0];
这将插入地图作为根视图的子视图(而不是replace根视图),留下你的其他视图(即button等)。 插入索引0将把它放在其他视图的下面。
将您的地图添加为子视图
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:coordinate.latitude longitude:coordinate.longitudeoom:6]; mapView = [GMSMapView mapWithFrame:self.view.bounds camera:camera];[self.view insertSubview:mapView atIndex:0];
现在,您可以拖放任何您的UIcontrolbutton,textfield它将在mapview上可见,或者也可以像上面那样添加为子视图。