gpt4 book ai didi

iphone - 如何将 UIImageView 添加到 MKOverlayRenderer?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:20:14 25 4
gpt4 key购买 nike

现在,由于它们在 MKOverlayView 中不再有 View ,并且它被称为 MKOverlayRenderer,我如何才能将 UIImageView 添加到我的 MKMapView 中?注意:我知道如何通过将图像绘制到 CGContextRef 上来将图像添加到 map 上,但我特别要求添加 UIImageView。谢谢!

最佳答案

这是添加 UIImage 的方法。如果您想添加 UIImageView,那么 Apple 文档说明 ( Apple Doc MKOverlayRenderer ):

It is recommended that you use Core Graphics to draw any content for your overlays. If you choose to draw using UIKit classes and methods instead, you must push the specified graphics context onto the context stack (using the UIGraphicsPushContext function) before making any drawing calls. When you are done drawing, you must similarly pop the graphics context off the stack using the UIGraphicsPopContext. Overlay drawing typically occurs on background threads to improve performance, so do not manipulate UIKit views or other objects that can only be manipulated on the app’s main thread.

#import <Foundation/Foundation.h>

@import MapKit;

@interface MyOverlayRenderer : MKOverlayRenderer

@end

和实现

#import "MyOverlayRenderer.h"

@implementation MyOverlayRenderer

- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context {
UIImage *image = [UIImage imageNamed:@"indigo_eiffel_blog.png"];
CGImageRef imageReference = image.CGImage;

MKMapRect theMapRect = [self.overlay boundingMapRect];
CGRect theRect = [self rectForMapRect:theMapRect];

CGContextScaleCTM(context, 1.0, -1.0);
CGContextTranslateCTM(context, 0.0, -theRect.size.height);

CGContextDrawImage(context, theRect, imageReference);
}

@end

关于iphone - 如何将 UIImageView 添加到 MKOverlayRenderer?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19473108/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com