为什么Google地图不适合我的UIView?

Pan*_*ngu 1 xcode google-maps objective-c ios

我已经创建了一个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];
}
Run Code Online (Sandbox Code Playgroud)

Lyn*_*ott 9

我怀疑你的界面不一定适合iPhone 6,所以当你设置mapView框架时viewDidLoad,尽管它最初适合你的内部googleMapView,在自动布局发生后,googleMapView延伸以适应屏幕和mapView保持相同的尺寸,这太小了.

为了解决这个问题,我建议你将代码移动到viewDidLayoutSubviews:所以你的mapView框架在googleMapView拉伸以填充屏幕后设置,例如:

- (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];
}
Run Code Online (Sandbox Code Playgroud)