3

I'm wondering if anyone else has the issue that MKMapView (Or maybe it relates to many other Views?) does a strange thing where it defaults to 1000x1000 in size the first time I load a screen. When I segue to another screen, and segue back to the map screen, then it actually followed up all my constraints.

This didn't happen with Xcode7 and I wonder if someone knows there's a known bug in Xcode8 or something?

MapKitView get loaded programmatically and is added as a subview within my View that has the constraints.

MKMapView *mapkitView = [[MKMapView alloc] initWithFrame:self.aConstrainedView.frame];
[self.mapkitView setDelegate:self];
[self.mapkitView setShowsUserLocation:YES];
[self.mapkitView setRotateEnabled:NO];
[self.aConstrainedView addSubview:self.mapkitView];

Could this be related to Autoresizing issue in Xcode 8 ?

Community
  • 1
  • 1
  • what's the prob exactly ? – vaibhav Sep 28 '16 at 11:54
  • The problem is that the map is not following the size of the parent View. Investigating with the "Debug View Hierarchy" showed that the MKMapView had a size of 1000x1000 and was out of bounds to the parent view.. – Lennaert van Dijke Sep 28 '16 at 11:56
  • set the frame size of mapView in inside program see my ans below .. – vaibhav Sep 28 '16 at 12:13
  • I'm seeing something similar with a storyboard-created MKMapView. Possibly related to [this bug](http://www.openradar.me/28325425) in Xcode 8? – Arnaud Oct 03 '16 at 19:24
  • Exactly encountered the same issue in xcode 8. Map changes when i reopens xcode and the my application and go to my view controller in storyboard where the mapview is present. All the constraints fail – Rajan Maheshwari Oct 22 '16 at 12:59

1 Answers1

1

Your initialiser should use the bounds of its superview, not the frame:

MKMapView *mapkitView = [[MKMapView alloc] initWithFrame:self.aConstrainedView.bounds];

Set a breakpoint on this line and in the debugger use:

(lldb) po self.aConstrainedView.bounds 

to ensure the width and height are correct. If you're adding the map view in viewDidLoad, then that's too early. You should override:

- (void)viewDidLayoutSubviews {
    dispatch_once(
        // Add map view here
    );
}

and add your code in there, as that gets called after your subviews have all been laid out according to your constraints.

norders
  • 1,160
  • 9
  • 13