ios - 旋转注释自定义图像
<p><div>
<aside class="s-notice s-notice__info post-notice js-post-notice mb16"role="status">
<div class="d-flex fd-column fw-nowrap">
<div class="d-flex fw-nowrap">
<div class="flex--item wmn0 fl1 lh-lg">
<div class="flex--item fl1 lh-lg">
<b>已结束。</b>此问题需要<a href="https://stackoverflow.com/help/minimal-reproducible-example" rel="noreferrer noopener nofollow">debugging details</a> .它目前不接受答案。
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我遇到了同样的问题,我有一个似乎可行的解决方案。</p>
<p>您需要首先制作一个自定义注释,以保存您想要的数据(例如坐标、您的飞机航向)。当您遍历数据时,请确保您使用的是该自定义注释。例如</p>
<pre><code>CustomAnnotation* annotation = [ init];
annotation.coordinates = ...
annotation.bearing = ...
</code></pre>
<p>然后在您的 <code>viewForAnnotation</code> 方法中,您可以通过执行类似的操作来获取该信息</p>
<pre><code>if (]) {
CustomAnnotation* myAnn = (CustomAnnotation*)annotation;
double bearing = myAnn.bearing; // or whatever it's called
...
}
</code></pre>
<p>希望这会有所帮助。</p>
<p><strong>编辑</strong>:为了旋转图像,我在某处找到了以下代码片段。它有效,但它会使您的图像有点像素化。</p>
<pre><code>@interface UIImage (RotationMethods)
- (UIImage *)imageRotatedByDegrees:(CGFloat)degrees;
@end
@implementation UIImage (RotationMethods)
static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;};
- (UIImage *)imageRotatedByDegrees:(CGFloat)degrees
{
// calculate the size of the rotated view's containing box for our drawing space
UIView *rotatedViewBox = [ 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), );
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
@end
</code></pre>
<p>将其粘贴在您的 .m 文件中,现在您可以在任何 UIImage 上执行 <code>;</code></p>
<p>所以现在在您的 <code>viewForAnnotation</code> 方法中,您可以执行类似的操作</p>
<pre><code>UIImage* image = [ imageRotatedByDegrees:degrees];
annView.image = image;
</code></pre></p>
<p style="font-size: 20px;">关于ios - 旋转注释自定义图像,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/30068060/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/30068060/
</a>
</p>
页:
[1]