[英]addSubView() and bringSubViewToFront() in viewDidLoad() not working
Im building a application that uses the Google Maps SDK. 我正在构建一个使用Google Maps SDK的应用程序。 For that aim I defined the view (root view) as a the mapView.
为此,我将视图(根视图)定义为mapView。 Now I am adding another view which I want to be on top of the mapView, but when I do that in viewDidLoad() its just not happening.
现在,我要添加另一个视图,使其位于mapView的顶部,但是当我在viewDidLoad()中执行此操作时,它只是没有发生。 I would really appreciate help and even an explanation of why that happens...topViewBar is just a UIView I added in Storyboard.
我非常感谢您的帮助,甚至解释为什么会发生这种情况... topViewBar只是我在Storyboard中添加的UIView。
class MapViewController: UIViewController {
@IBOutlet weak var topViewBar: UIView!
override func viewDidLoad() {
super.viewDidLoad()
//MARK: - put event on map function
func putEventOnMAp(latitude: CLLocationDegrees, longitude: CLLocationDegrees, eventInfo: String, map: GMSMapView) {
let marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(latitude, longitude)
marker.title = eventInfo
marker.map = map
}
//MARK: - Initialize map view
let camera = GMSCameraPosition.cameraWithLatitude(-33.86,
longitude: 151.20, zoom: 6)
let mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
mapView.myLocationEnabled = true
self.view = mapView
self.view.addSubview(topViewBar) // these two lines is where I try to add the additional view
self.view.bringSubviewToFront(topViewBar)
let marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20)
marker.title = "Sydney"
marker.snippet = "Australia"
marker.map = mapView
You're adding topViewBar
as a subview of mapView
. 您将
topViewBar
添加为mapView
的子视图。 I think what you want to do is initialize a simple container UIView
to set self.view
to. 我认为您想要做的是初始化一个简单的容器
UIView
来将self.view
设置为。 Then add mapView
and topViewBar
both as subviews of the UIView
. 然后将
mapView
和topViewBar
都添加为UIView
子视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.