Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Map Annotations in iOS 6 don't stay rotated when user pans the map

Tags:

ios

iphone

Would really love an answer to this question https://devforums.apple.com/message/723468. I can't post the details because its about iOS 6 and is Confidential per Apple.

Please post the answers/comments to the Apple Dev forums post and let me know about it here.

EDIT: Since iOS6 is officially released:

In my pre-ios6 code I'm doing this to rotate the map when the user location moves:

//this is in my MKMapViewDelegate
-(void) rotateMap:(MKMapView *)mapViewTmp forLocation:(MKUserLocation *) userLocation {
     ...
     //calculate needed rotation
     ...
     [mapViewTmp setTransform:CGAffineTransformMakeRotation(lastRotation)]; //rotate the MKMapView

     for (id<MKAnnotation> annotation in mapViewTmp.annotations) {
           MKAnnotationView* annotationView =[mapViewTmp viewForAnnotation:annotation];

                    [annotationView setTransform:CGAffineTransformMakeRotation(-lastRotation)];      //counter rotate the Annotation Views

                    [annotationView setNeedsDisplay];  //ios6
     }

}

And this worked fine (1000s of users).

In ios6 however (I updated Xcode/sdk on 9/4/2012), the annotation views do not maintain this rotation (for example if map is panned). They flip back to their non rotated state (which, since my map is rotated means they show text at an angle instead of horizontal).

The code does temporarily rotate the annotations so their text appears horizontal, but if map is panned (and their seem to be other causes as well) then the annotations flip to their non-rotated state and my annotation text appears at an angle relative to the rotated map.

What is the correct way to rotate an MKAnnotationView so that it stays rotated in IOS6? What has changed in MKMapView that caused the change?

like image 232
Fraggle Avatar asked Sep 07 '12 20:09

Fraggle


3 Answers

The fix for this is to do the following in the viewForAnnotation method:

// iOS6 BUG WORKAROUND !!!!!!!
if (is6orMore) {
     [annotationView setTransform:CGAffineTransformMakeRotation(.001)]; //any small positive rotation
}

This was posted as a comment by me in the original question and then posted by cristis as an answer (referencing my comment), but I'm posting and accepting my own answer since it was me that came up with it. Did that make sense?

like image 58
Fraggle Avatar answered Nov 19 '22 17:11

Fraggle


This was posted as a comment, I'm re-posting it as an answer so anyone can see it easily (and waste less time trying to figure it out).

And the fix is===>in viewForAnnotation method:

// iOS6 BUG WORKAROUND !!!!!!!
if (is6orMore) {
     [annotationView setTransform:CGAffineTransformMakeRotation(.001)]; 
}
like image 36
cristis Avatar answered Nov 19 '22 15:11

cristis


I saw the same thing. Here's the fix:

Set YOUR transform on the child of the MKAnnotationView, so in pseudo-ish code:

view.child.transform = CGAffineTransformMakeRotation(0.3);

Let them have control of the annotation view and take control of your view subtree. Transforms concatenate and you'll inherit whatever they do in position. Works for me on iOS 6.

like image 45
user1735208 Avatar answered Nov 19 '22 15:11

user1735208