GMSMapView隐藏导航栏

时间:2013-06-25 23:01:39

标签: iphone ios google-maps cgrect google-maps-sdk-ios

我通过Googla Maps iOS SDK实现了GMSMapView

来自Google的示例代码建议或多或少地声明视图只是在代码中删除此方法

- (void)loadView {
    // Create a GMSCameraPosition that tells the map to display the
    // coordinate -33.86,151.20 at zoom level 6.
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
                                                            longitude:151.20
                                                                 zoom:6];
    mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
    mapView_.myLocationEnabled = YES;
    self.view = mapView_;

    // Creates a marker in the center of the map.
    GMSMarker *marker = [[GMSMarker alloc] init];
    marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
    marker.title = @"Sydney";
    marker.snippet = @"Australia";
    marker.map = mapView_;
}

它自动运行,但mapView碰巧覆盖了我的navigationItem 很明显,地图在initWithFram:CGRectZero中占据了它的维度 但只需将参数更改为自定义CGRect

CGRect square = CGRectMake(100, 100, 100, 100);

没有为我工作,还有其他建议吗? 我只需要在导航项和标签栏之间显示地图(但第二部分不会被覆盖)

Google maps covering nav bar

2 个答案:

答案 0 :(得分:1)

确保地图的视图控制器是UINavigationController的导航堆栈的一部分。我将带有地图和列表标签的UITabBarController推送到UINavigationController中嵌入的视图控制器上没有问题。这样导航栏视图仅属于UINavigationController,地图控制器视图不应覆盖它。

答案 1 :(得分:1)

问题是mapView_被设置为整个视图

self.view = mapView_;

计算正确的尺寸并将其添加为子视图是解决问题的正确方法

CGRect f = self.view.frame;
CGRect mapFrame = CGRectMake(f.origin.x, 44, f.size.width, f.size.height);
mapView_ = [GMSMapView mapWithFrame:mapFrame camera:camera];
[self.view addSubview:mapView_];