已结束。此问题需要
debugging details .它目前不接受答案。
Best Answer-推荐答案 strong>
我遇到了同样的问题,我有一个似乎可行的解决方案。
您需要首先制作一个自定义注释,以保存您想要的数据(例如坐标、您的飞机航向)。当您遍历数据时,请确保您使用的是该自定义注释。例如
CustomAnnotation* annotation = [[CustomAnnotation alloc] init];
annotation.coordinates = ...
annotation.bearing = ...
然后在您的 viewForAnnotation
方法中,您可以通过执行类似的操作来获取该信息
if ([annotation isKindOfClass:[CustomAnnotation class]]) {
CustomAnnotation* myAnn = (CustomAnnotation*)annotation;
double bearing = myAnn.bearing; // or whatever it's called
...
}
希望这会有所帮助。
编辑:为了旋转图像,我在某处找到了以下代码片段。它有效,但它会使您的图像有点像素化。
@interface UIImage (RotationMethods)
- (UIImage *)imageRotatedByDegreesCGFloat)degrees;
@end
@implementation UIImage (RotationMethods)
static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;};
- (UIImage *)imageRotatedByDegreesCGFloat)degrees
{
// calculate the size of the rotated view's containing box for our drawing space
UIView *rotatedViewBox = [[UIView alloc] initWithFrame:CGRectMake(0,0,self.size.width, self.size.height)];
CGAffineTransform t = CGAffineTransformMakeRotation(DegreesToRadians(degrees));
rotatedViewBox.transform = t;
CGSize rotatedSize = rotatedViewBox.frame.size;
// Create the bitmap context
//UIGraphicsBeginImageContext(rotatedSize); // For iOS < 4.0
UIGraphicsBeginImageContextWithOptions(rotatedSize, NO, 0.0);
CGContextRef bitmap = UIGraphicsGetCurrentContext();
// Move the origin to the middle of the image so we will rotate and scale around the center.
CGContextTranslateCTM(bitmap, rotatedSize.width/2, rotatedSize.height/2);
// Rotate the image context
CGContextRotateCTM(bitmap, DegreesToRadians(degrees));
// Now, draw the rotated/scaled image into the context
CGContextScaleCTM(bitmap, 1.0, -1.0);
CGContextDrawImage(bitmap, CGRectMake(-self.size.width / 2, -self.size.height / 2, self.size.width, self.size.height), [self CGImage]);
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
@end
将其粘贴在您的 .m 文件中,现在您可以在任何 UIImage 上执行 [someUIImage imageRotatedByDegrees:yourDegrees];
所以现在在您的 viewForAnnotation
方法中,您可以执行类似的操作
UIImage* image = [[UIImage imageNamed"yourImage.png"] imageRotatedByDegrees:degrees];
annView.image = image;
关于ios - 旋转注释自定义图像,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/30068060/