【问题标题】:GMSMapView hiding navigation barGMSMapView 隐藏导航栏
【发布时间】:2013-06-25 23:01:39
【问题描述】:

我通过 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);

没有为我工作,还有其他建议吗? 我只需要显示导航项和选项卡栏之间的地图(但第二个并没有被覆盖)

【问题讨论】:

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


    【解决方案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_];
    

    【讨论】:

    • 谢谢,这对 Swift 版本有帮助。不过,我想知道这是否是正确的方法,即依靠导航栏 (44) 的大小来偏移地图视图。
    【解决方案2】:

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

    【讨论】:

    • 你说得对,我有一个简单的 UIViewController,顶部有一个 NavigationItem,而不是 NavigationBar
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-28
    • 2019-12-27
    相关资源
    最近更新 更多