子类化 MKOVerlay View - canDrawMapRect 未调用

发布于 2024-11-28 07:33:56 字数 1386 浏览 1 评论 0原文

我正在尝试子类 MKOverlayView 以创建自定义叠加层。我知道为了做到这一点,必须重写以下两种方法

- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context;

- (BOOL)canDrawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale;

我的问题来自后一种方法。由于某种原因,当我在 MKOverlayView 子类中重写它时,它不会被调用。根据文档,应该在渲染图块之前调用它,如果它返回 YES,则调用drawMapRect。我希望有人可以看一下下面的代码,看看他们是否能找出为什么这个方法没有被调用。它是否意味着要在某处手动启用/调用?

有趣的是,drawMapRect确实被调用,只有 canDrawMapRect 没有被调用。我是否误解了 canDrawMapRect 的功能或者我的代码有问题?

HeatMapOverlay.h

#import <MapKit/MapKit.h>
#import <Foundation/Foundation.h>
@interface HeatMapOverlayView : MKOverlayView{
    ...variables...
}

@end

HeatMapOverlay.m

#import "HeatMapOverlayView.h"
#import <CoreGraphics/CoreGraphics.h>
#import <QuartzCore/QuartzCore.h>

@implementation HeatMapOverlayView
@synthesize points, heat, QualityIndex;
- (id)initWithOverlay:(id<MKOverlay>)overlay {
    self = [super init];
    if (self) {
        // Initialization code here.
    }
    return self;
}


- (BOOL)canDrawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale{
         ...complete check...
return NO;
}


- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext (CGContextRef)context{
...draw overlay...
}

谢谢!

I am attempting to subclass MKOverlayView to create a custom overlay. I understand that in order to do this, one must override the following two methods

- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context;

- (BOOL)canDrawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale;

My question arrises from the latter method. For some reason, when I override it in my MKOverlayView subclass, it does not get called. According to documentation, it should be called before tiles are rendered and if it returns YES, then drawMapRect is called. I was hoping that someone could look at the following code and see if they can figure out why this method is not being called. Is it meant to be enabled/called manually somewhere?

Interestingly enough, drawMapRect does get called, it's only canDrawMapRect that does not. Am I misinterpreting the functionality of canDrawMapRect or is something wrong in my code?

HeatMapOverlay.h

#import <MapKit/MapKit.h>
#import <Foundation/Foundation.h>
@interface HeatMapOverlayView : MKOverlayView{
    ...variables...
}

@end

HeatMapOverlay.m

#import "HeatMapOverlayView.h"
#import <CoreGraphics/CoreGraphics.h>
#import <QuartzCore/QuartzCore.h>

@implementation HeatMapOverlayView
@synthesize points, heat, QualityIndex;
- (id)initWithOverlay:(id<MKOverlay>)overlay {
    self = [super init];
    if (self) {
        // Initialization code here.
    }
    return self;
}


- (BOOL)canDrawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale{
         ...complete check...
return NO;
}


- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext (CGContextRef)context{
...draw overlay...
}

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怼怹恏 2024-12-05 07:33:56

尝试更改此行:

self = [super init];

对此,以便为 MKOverlayView 使用正确的初始值设定项:

self = [super initWithOverlay:overlay];

Try changing this line:

self = [super init];

to this to use the proper initializer for an MKOverlayView:

self = [super initWithOverlay:overlay];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文