Note that there are some explanatory texts on larger screens.

plurals
  1. PORestore MKMapView visible state/region properly
    primarykey
    data
    text
    <p>I have a little iPad app which shows a MKMapView instance (<code>map</code>). In order to save the state I try saving the <code>map.region</code> to the NSUserDefaults. This works very well storing only the single values as doubles. On launching, the app combines the numbers and produces a valid <code>MKCoordinateRegion</code>. This happens in <code>application:didFinishLaunchingWithOptions:</code>. Now there are several problems.</p> <p><strong>1)</strong> Imagine: You leave the app in landscape orientation. The app saves the corresponding <code>MKCoordinateRegion</code>. The app is terminated. Now, holding the iPad landscape, launching the app, the map doesn't show the same state as before leaving the app. And no, this is not a problem of <code>regionThatFits:</code>. I tracked it down and this is what happens: Also when it isn't visible to the user, the app starts in portrait mode. The app restores his state. After that the map is rotated into landscape mode.</p> <p>With other words the app saves the landscape state but restores it to portrait. If you repeat these steps the map zooms out with every launch. Not the best UX.</p> <p><strong>2)</strong> Even if problem one would be solved by restoring in the right orientation there is still the problem that the launching orientation could differ from the leaving orientation. I think one of the better ways to solve this is to store always the values for the portrait orientation also when the user leaves in landscape. By doing this the state would be restored properly because the app is launched initially in portrait by the system.</p> <p>One possible way would be to change the latitude/longitude values if the app is left in landscape. But this would be too inaccurate because <code>CLLocationDegrees</code> differ if they are latitude or longitude.</p> <p>An other way (and I think this would be the best way) would be to "simulate" a rotation of the mapview or to calculate the visible region for the portrait mode when the app is left. But I really don't know how to do this. Here is the point where I need your help and your ideas.</p> <p>I appreciate every ray of hope. :) — And please tell me if I think into a wrong direction.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload