4

If a callout is showing when I rotate the phone from vertical regular to vertical compact, the callout is partially under the navigation bar after rotation.

How can I get the callout to end up completely enclosed within the map?

Callout Cuff Off This is the phone in vertical compact. I cut off some of the screen for proprietary reasons.

Edit 2

A local community member posted the following code to prevent the zooming in willTransitionTo that I complained about below.

if let annotation = self.mapView.selectedAnnotations.first {
    var region = self.mapView.region
    region.center = annotation.coordinate
    self.mapView.setRegion(region, animated: true)
}

It works like a champ to prevent the zooming and only results in the centering. Unfortunately, the callout is still partially off screen. If I change the setCenter when a pin is selected, it unfortunately results in the callouts being offscreen in a different way. (Something that I already found a hacky workaround regarding deselecting/selecting that is kind of referenced below.)

Edit 1

  • I have discovered that for some reason calling setCenter is also resulting in zooming and I can find no where that I'm causing that. So, that's not good.
  • I tried centering on the annotation during willTransitionTo. This did not change where the callout is at all and just zooms the map. (See point above.)
  • I tried deselecting and then reselecting the annotation in willTransitionTo. I get a long pause between the callout disappearing and reappearing. Also, there's zooming (see above). However, the callout is within the frame of the map. I am not going with this option because of the "flash" and zooming. (Was making me sea sick.)

Old Proposed Answer

Although I still think this is a valid point on its own

  • An SE in landscape with more stuff under the map is just too short to have a functional map.

What I Have Tried

  • regionDidChange is not called then the device is rotated
  • I tried to check the frame of the annotation view on rotation (willTransitionTo). The frame is already contained in the maps frame
  • I confirmed that the top of my map view is pinned to the top layout guide
  • I looked at the view hierarchy debugger, and it appears that there are three "private" elements with an origin outside of the map view, but I don't know what to do with this information. (The first UIView contained in the MKPinAnnotationView, _UIPopoverView, and the UIView contained in the UIView contained in the _MKCalloutBackgroundMaskView)
  • I am not setting a specific frame in viewForAnnotation

Other Notes That Might Be Relevant

  • I am doing some odd stuff with changing the property on canShowCallout because I want to center on the pin after it is selected. But the problem is on rotation, and this code is not getting called again on rotation.
  • I do need to account for an SE in "landscape," which might be part of the problem.

All help is appreciated. Especially being shown in a direction to read, etc.

Amelia
  • 185
  • 2
  • 9

1 Answers1

1

A coworker pointed me to this answer to MKAnnotation image offset with custom pin image.

I am now setting

annotationView.layer.anchorPoint = CGPoint(x: 0, y: 0)

in viewFor annotation and it is working.

I honestly don't understand why this is fixing the problem, so comments/edits/answers explaining why would be greatly appreciated.

Community
  • 1
  • 1
Amelia
  • 185
  • 2
  • 9