GMSMapView中的AutoLayout
问题描述:
我在特定的视图中需要GMSMapView。这里viewForGMSMapView是我的UIView。我使用了下面的代码。GMSMapView中的AutoLayout
let camera = GMSCameraPosition.cameraWithLatitude(-33.86, longitude: 151.20, zoom: 6.0)
let mapView = GMSMapView.mapWithFrame(viewForGMSMapView.bounds, camera: camera)
mapView.translatesAutoresizingMaskIntoConstraints = true;
mapView.myLocationEnabled = true
viewForGMSMapView.addSubview(mapView)
它有助于解决我的看法。但是,当设备屏幕增加时,它会失败。如何自动布局这个GMSMapView。我需要它适合我的视图
答
如果你想translatesAutoresizingMaskIntoConstraints
为true
,你需要设置一个合适的autoresizingMask
,使其正确调整或收缩。
尝试:
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
否则,您需要设置translatesAutoresizingMaskIntoConstraints
到false
并建立约束地图视图。