简体   繁体   中英

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:

在此处输入图片说明

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...

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM