简体   繁体   English

GMSMapView隐藏导航栏

[英]GMSMapView hiding navigation bar

I implemented the GMSMapView via the Googla Maps iOS SDK 我通过Googla Maps iOS SDK实现了GMSMapView

the example code from Google suggests to declare the view more or less just dropping this method in your code 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_;
}

it automagically works, but the mapView happens to cover my navigationItem it's clear that the maps take its dimension at the initWithFram:CGRectZero but simply changing the parameter to a custom CGRect 它可以自动运行,但是mapView恰好覆盖了我的navigationItem,很明显,地图在initWithFram:CGRectZero处具有其尺寸,而只是将参数更改为自定义CGRect

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

haven't worked for me, any other suggestion? 还没有为我工作,还有其他建议吗? i only need to display the map between the Nav Item and the Tab Bar (but the second doesn't happen to be covered) 我只需要显示导航项目和标签栏之间的地图(但第二个就不会被覆盖)

谷歌地图覆盖导航栏

Make sure your view controller for the map is part of a navigation stack of a UINavigationController . 确保您的地图视图控制器是UINavigationController导航堆栈的一部分。 I had no problems pushing a UITabBarController with a map and a list tab onto a view controller embedded in a UINavigationController . 我将带有地图和列表选项卡的UITabBarController推入嵌入UINavigationController的视图控制器中没有问题。 This way the navigationbar view belongs only to the UINavigationController and the map controller view shouldn't cover it. 这样,导航UINavigationController视图仅属于UINavigationController ,而地图控制器视图不应覆盖该视图。

The problem was that the mapView_ was being set as the whole view 问题是mapView_被设置为整个视图

self.view = mapView_;

calculating the correct dimension and adding it as a subview was the correct way to solve it 计算正确的尺寸并将其添加为子视图是解决它的正确方法

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_];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM