【问题标题】:Why doesn't Google Maps stretch to fit my UIView?为什么 Google 地图不能拉伸以适应我的 UIView?
【发布时间】:2018-11-17 11:24:37
【问题描述】:

我创建了一个 UIView,我想将谷歌地图放入其中。但是,当我将 GMSMapview 添加到我的 UIView 时,GMSMapview 的底部不会扩展以适应 UIView。我仍然可以看到 UIVIew 的灰色部分。

这是为什么呢?

- (void)viewDidLoad 
{
    // Create a GMSCameraPosition that tells the map to display the
    // coordinate -33.86,151.20 at zoom level 6.
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.868
                                                            longitude:151.2086
                                                                 zoom:6];
    GMSMapView *mapView = [GMSMapView mapWithFrame:self.googleMapView.bounds camera:camera];



    [self.googleMapView addSubview:mapView];
}

【问题讨论】:

    标签: ios objective-c xcode google-maps


    【解决方案1】:

    我怀疑你的界面不一定适合 iPhone 6,所以当你在viewDidLoad 中设置mapView 框架时,虽然它最初适合你的googleMapView,但在自动布局发生后,googleMapView 会伸展以适应屏幕,mapView 保持相同的大小,这太小了。

    要解决此问题,我建议将您的代码移动到 viewDidLayoutSubviews:,以便在 googleMapView 拉伸以填充屏幕后设置您的 mapView 框架,例如:

    - (void)viewDidLayoutSubviews {
        [super viewDidLayoutSubviews];
        GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.868
                                                                longitude:151.2086
                                                                     zoom:6];
        GMSMapView *mapView = [GMSMapView mapWithFrame:self.googleMapView.bounds camera:camera];
        [self.googleMapView addSubview:mapView];
    }
    

    【讨论】:

    【解决方案2】:

    如果您在 Xcode 7 上遇到此问题,对我有用的方法(接受的答案不适用于我,因为我正在使用 Swift 开发)是检查 GMSMapView 及其的“自动调整子视图”框父母(对我来说是UIStackView)。

    【讨论】:

      【解决方案3】:

      viewDidAppear

      侧添加布局
          override func viewDidAppear(_ animated: Bool){
              super.viewDidAppear(animated) 
              //google map setup here
          }
      

      【讨论】:

        猜你喜欢
        • 2012-11-06
        • 2013-08-22
        • 2010-11-13
        • 1970-01-01
        • 2014-03-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多