2014-12-07 53 views
0

我已经创建了一个UIView,我想将Google地图放进去。但是,当我将GMSMapview添加到我的UIView时,GMSMapview的底部不会扩展到适合UIView。我仍然可以看到我UIVIew的灰色部分。为什么Google地图不适合我的UIView?

这是为什么?

enter image description here

- (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]; 
} 

回答

5

我怀疑你的界面不一定大小为iPhone 6,所以当你设置viewDidLoadmapView框架,虽然它最初适合你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]; 
} 
+0

谢谢你lyndsey,我标记你的解决方案。你可以看看我的另一篇关于谷歌地图的帖子吗?没有人似乎知道这个问题:(谢谢:http://stackoverflow.com/questions/26772521/why-is-google-maps-sdk-not-working-on-iphone-6-ios-8 – Pangu 2014-12-07 06:25:26

+0

谢谢,工作对我来说 – 2017-11-16 08:58:00

+0

英雄!为我们解决了很多问题 – Zach 2018-01-09 21:40:02

0

如果您有关于Xcode的7这个问题,什么对我有效(我接受的答案不适用于我,因为我在Swift中开发)正在检查GMSMapView及其父(对于我来说是UIStackView)的“Autoresize Subviews”框。