我正在使用ios应用程序,我希望在同一个超级视图中显示谷歌地图视图和包含位置信息的文本标签。我预期的情况是地图视图填满整个屏幕,文本标签悬停在它上面。当我这样做时,我在代码中创建地图视图,但从界面构建器中的对象库中拖动标签。但是,在调用ViewDidLoad之前,似乎IB中的控件将被初始化。因此view.addSubview(mapView)
将添加地图视图,但涵盖IB中的所有控件。如果我还想使用IB构建我的UI,有没有办法解决这个问题?谢谢!
override func viewDidLoad() {
super.viewDidLoad()
// Set up Maps
locationManager = CLLocationManager()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
locationManager.distanceFilter = 50
locationManager.startUpdatingLocation()
locationManager.delegate = self
placesClient = GMSPlacesClient.shared()
let defaultLocation = CLLocation(latitude: -33.86, longitude: 151.20)
let camera = GMSCameraPosition.camera(withLatitude: defaultLocation.coordinate.latitude,
longitude: defaultLocation.coordinate.longitude,
zoom: zoomLevel)
mapView = GMSMapView.map(withFrame: view.bounds, camera: camera)
mapView.settings.myLocationButton = true
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
mapView.isMyLocationEnabled = true
// Add the map to the view, hide it until we've got a location update.
view.addSubview(mapView)
mapView.isHidden = true
}