[英]GMSMapView hiding navigation bar
我通过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);
还没有为我工作,还有其他建议吗? 我只需要显示导航项目和标签栏之间的地图(但第二个就不会被覆盖)
确保您的地图视图控制器是UINavigationController
导航堆栈的一部分。 我将带有地图和列表选项卡的UITabBarController
推入嵌入UINavigationController
的视图控制器中没有问题。 这样,导航UINavigationController
视图仅属于UINavigationController
,而地图控制器视图不应覆盖该视图。
问题是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_];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.