iosmkmapviewmkpinannotationviewautolayout

MKMapView click on pin causes weird frame changes


I created not custom, simple pin annotations on MKMapView and when I click on it, I'm getting following for my MapView:

enter image description here

It happens only on iOS8.

I figured out that without constraints for mapView - it works fine. Constraints are simple - just to be fullscreen when rotating device. here are they:

[self.mapView setTranslatesAutoresizingMaskIntoConstraints:NO];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.mapView
                                                          attribute:NSLayoutAttributeWidth
                                                          relatedBy:NSLayoutRelationEqual
                                                             toItem:self.view
                                                          attribute:NSLayoutAttributeWidth
                                                         multiplier:1.0
                                                           constant:0]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.mapView
                                                          attribute:NSLayoutAttributeHeight
                                                          relatedBy:NSLayoutRelationEqual
                                                             toItem:self.view
                                                          attribute:NSLayoutAttributeHeight
                                                         multiplier:1.0
                                                           constant:0]];

MapView is added to ViewController.view and I'm not getting any warnings about conflicting constraints so on.

Why it happens? And what is most unfair why clicking on MapView annotation causes it...


Solution

  • I didn't go to details but for some reasons mapView after clicking on annotation had a center in left/top corner of parent view,

    so setting center anchor did the trick:

    [self.mapView.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor].active = true;
    [self.mapView.centerYAnchor constraintEqualToAnchor:self.view.centerYAnchor].active = true;
    

    I guess this is because I specified height/width constraints but nothing about positioning, so defining top/left constraints, also could help