0

I've designed the following layout on XCode:

enter image description here

The button Layout (Cancel, Sign Up) is pinned to the bottom layout guide. On top of that are 3 equally sized UIViews, each with 1px vertical spacing in between them.

The remaining space is occupied by mapView, which is a UIView. It is pinned to the top, leading and trailing layout guide. It also has 8px spacing between the building number view.

When I run the application on my iPhone 6, I get this:

enter image description here

The map is not drawn in all available space. I don't know why:

When setting up the map, I do pass the bounds of the mapView:

class RegisterAddressViewController: BaseViewController, CLLocationManagerDelegate, GMSMapViewDelegate {

    @IBOutlet var mapView : UIView!

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        self.setupMapView()
        self.setupLocationManager()
    }

    func setupMapView(){
        let camera = GMSCameraPosition.cameraWithLatitude(-33.86,
                                                          longitude: 151.20, zoom: 6)
        self.gmsMapView = GMSMapView.mapWithFrame(self.mapView.bounds, camera: camera)
        self.gmsMapView!.delegate = self
        self.mapView.addSubview(self.gmsMapView!)
    }

    //...
}

I do not believe it's an AutoLayout issue since no warning appears in the console and the light grey background of the mapView indicates that the layout is set correctly.

Is there some configuration that I'm missing? Thanks.

1 Answer 1

1

The issue is that Auto Layout hasn't run and sized your views at the time of viewWillAppear. Move your code into an override of viewDidLayoutSubviews and it should work correctly. Be careful though, because viewDidLayoutSubviews can run multiple times, so check for that and only do your setup once or make sure it is OK to run setupMapView multiple times.

1
  • Judging by the name, I thought viewDidLayoutSubviews was already done by the time viewWillAppear gets called. My bad, I should have read in to the documentation to be sure. Thanks mate!
    – W.K.S
    Jun 26, 2016 at 15:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.