Search code examples
iosswiftswiftuimapkitipados

set individual Area inside Map in MapKit


I am trying to set an individual Frame which defines the visible area of the Map.

Currently all the annotations are shown with mapView.showAnnotations but they aligned to fit in the whole iPad screen view. So they are partially hidden by Floating UI Elements (Green). Also the center of the screen is aligned to be the center of the iPad screen.

current ipad view

What I try to accomplish: I want something like a defined rectangle inside the Map to be the only regarded area in the map. But the Map itself (blue) shall still be shown behind the UI Elements.

goal ipad view

I thought it would be able to accomplish this by using setVisibleMapRect but when I ever I try to use this it does not take any effect. Is setVisibleMapRectactually the needed method to solve this problem?


Solution

  • The actual answer I found out later is defining

    mapView.layoutMargins = UIEdgeInsets(top: X, left: X, bottom: X, right: X)

    so the map wont use the space defined by the margin