[英]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.