2013-06-25 206 views
1

我通过Googla地图iOS版SDKGMSMapView中隐藏导航栏

从谷歌代码示例说明申报的观点或多或少只是删除这个方法在你的代码

- (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_; 
} 

它自动地实现通过GMSMapView作品,但mapView恰好覆盖了我的导航项目 很明显,这些地图的尺寸​​在initWithFram:CGRectZero ,但只是将参数更改为自定义CGRect

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

有没有为我工作,任何其他建议? 我只需要显示导航项目和标签栏之间的映射(但第二不会发生被覆盖)

Google maps covering nav bar

回答

2

的问题是,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_]; 
+0

谢谢,这有助于Swift版本。不过,我想知道,如果这是正确的方法,即依靠导航栏(44)的大小来抵消地图视图。 – Eduardo

1

确保您的地图视图控制器是一个导航的一部分一堆UINavigationController。将UITabBarController带有地图和列表选项卡嵌入UINavigationController中的视图控制器中,我没有任何问题。这样导航栏视图只属于UINavigationController,地图控制器视图不应该覆盖它。

+0

你做了一个正确的方法点,我有一个简单的UIViewController顶部NavigationItem,而不是NavigationBar – Zerho