ios - 当用户平移 map 时,iOS 6 中的 map 注释不会保持旋转

标签 ios iphone

真的很想回答这个问题https://devforums.apple.com/message/723468 .我无法发布详细信息,因为它是关于 iOS 6 的,并且是 Apple secret 。

请将答案/评论发布到 Apple Dev 论坛帖子,并在此处让我知道。

编辑:自 iOS6 正式发布以来:

在我的 ios6 之前的代码中,我这样做是为了在用户位置移动时旋转 map :

//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
     }

}

这很好用(1000 位用户)。

但是在 ios6 中(我在 2012 年 9 月 4 日更新了 Xcode/sdk),注释 View 不保持这种旋转(例如,如果 map 被平移)。它们会翻转回它们的非旋转状态(因为我的 map 是旋转的,这意味着它们会以一定角度而不是水平方式显示文本)。

代码确实临时旋转了注释,因此它们的文本显示为水平,但是如果 map 被平移(并且它们似乎也是其他原因),则注释翻转到它们的非旋转状态并且我的注释文本出现在一个角度相对于旋转的 map 。

旋转 MKAnnotationView 以使其在 IOS6 中保持旋转的正确方法是什么? MKMapView 中发生了什么变化导致了变化?

最佳答案

解决这个问题的方法是在 viewForAnnotation 方法中执行以下操作:

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

这是我在原始问题中作为评论发布的,然后由 cristis 作为答案发布(引用我的评论),但我发布并接受我自己的答案,因为是我提出的。这有意义吗?

关于ios - 当用户平移 map 时,iOS 6 中的 map 注释不会保持旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12324765/

相关文章:

iphone - iOS 设备未在 Xcode 中列出

javascript - 如何通过 JavaScript 以编程方式在 iPhone 上的 Mobile Safari 中显示地址栏?

ios - 在 iOS 6 中将委托(delegate)设置为 nil

iphone - UIBarButtonItem 突出显示颜色

ios - JSON AnyObject 到 Bool 的转换总是返回 nil

android - 使用本地和服务器页面的 PhoneGap jQuery-Mobile 应用程序

ios - WKWebView 从 WKBackForwardList 中删除一项

iphone - 正确加载和处理 XML 而不会浪费内存

ios - 带协议(protocol)的 Swift 类扩展 vs 遵守协议(protocol)

ios - Xcode 7.2 更新后,可执行文件使用无效权利进行签名