English 中文(简体)
c. 激发新思维 地图:电话
原标题:setNeedsDisplayInMapRect doesn t trigger new drawMapRect: call

I m 采用一种习俗MKOverlay/MKOverlayView,用我自己的手法完全覆盖谷歌基图,这些都装满了同步。 在我收到<条码>扫描MapRect:zoomScale:时,我照常要求卸载的碎片。 下面请我的透视(并在此案中回复FALSE),然后打电话setNeedsDisplayInMapRect:zoomScale:, 一旦具备这些功能的话。

这通常都是行之有效的,似乎完全在模拟器中工作。

然而,在装置上,我有时在超支中发现一个漏洞——一个缺失的碎片。

我可以看到,请求是徒劳的,请求是完整的。 我可以看到,我打电话setNeedsplayInMapRect:zoomScale:,我通过原来的<代码>MKMapRect和MKZoomScale,载于canDrawMapRect:zoomScale:。 但是,我也看到,从来不要求超支重塑这种无能(要么canDrawMapRect:zoomScale:,要么drawMapRect:zoomScale:inContext:,要么再次要求这样做。

我需要理解为什么发生这种情况以及如何纠正。

这里是我方济会国际的相关守则。 观点子类:

- (BOOL) canDrawMapRect: (MKMapRect) mapRect zoomScale: (MKZoomScale) zoomScale 
{
    NSUInteger zoomLevel = [self zoomLevelForZoomScale:zoomScale];
    CGPoint mercatorPoint = [self mercatorTileOriginForMapRect:mapRect];
    NSUInteger tilex = floor(mercatorPoint.x * [self worldTileWidthForZoomLevel:zoomLevel]);
    NSUInteger tiley = floor(mercatorPoint.y * [self worldTileWidthForZoomLevel:zoomLevel]);

    NSURL* tileUrl = [self tileURLForZoomLevel: zoomLevel tileX: tilex tileY: tiley];

    ASIHTTPRequest* tileRequest = [ASIHTTPRequest requestWithURL: tileUrl];
    tileRequest.downloadCache = [ASIDownloadCache sharedCache];
    [tileRequest setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];

    if ( NO == [[ASIDownloadCache sharedCache] isCachedDataCurrentForRequest: tileRequest] )
    {
        [tileRequest setCachePolicy: ASIAskServerIfModifiedWhenStaleCachePolicy];
        tileRequest.delegate = self;
        tileRequest.userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
                                [NSValue value: &mapRect withObjCType: @encode( MKMapRect )],       @"mapRect",
                                [NSValue value: &zoomScale withObjCType: @encode( MKZoomScale )],   @"zoomScale",
                                [NSNumber numberWithInt: tilex], @"tilex",
                                [NSNumber numberWithInt: tiley], @"tiley",
                                nil];

        [_tileRequestStack addOperation: tileRequest];

        NSLog( @"canDrawMapRect: %d, %d - REQUESTING", tilex, tiley );

        return NO;
    }

    NSLog( @"canDrawMapRect: %d, %d - READY", tilex, tiley );

    return YES;
}

- (void) drawMapRect: (MKMapRect) mapRect zoomScale: (MKZoomScale) zoomScale inContext: (CGContextRef) context 
{
    NSUInteger zoomLevel = [self zoomLevelForZoomScale:zoomScale];

    CGPoint mercatorPoint = [self mercatorTileOriginForMapRect:mapRect];

    NSUInteger tilex = floor(mercatorPoint.x * [self worldTileWidthForZoomLevel:zoomLevel]);
    NSUInteger tiley = floor(mercatorPoint.y * [self worldTileWidthForZoomLevel:zoomLevel]);

    NSLog( @"drawMapRect:  %d, %d", tilex, tiley );

    NSURL* tileUrl = [self tileURLForZoomLevel: zoomLevel tileX: tilex tileY: tiley];
    NSData* tileData = [[ASIDownloadCache sharedCache] cachedResponseDataForURL: tileUrl];

    UIGraphicsPushContext(context);

    if ( tileData != nil )
    {
        UIImage* img = [UIImage imageWithData: tileData];

        if ( img != nil )
        {
            [img drawInRect: [self rectForMapRect: mapRect] blendMode: kCGBlendModeNormal alpha: 1.0 ];
        }
        else 
        {
            NSLog( @"oops - no image" );
        }

        CGSize s = CGContextConvertSizeToUserSpace( context, CGSizeMake( 40, 1 ));

        UIFont* f = [UIFont systemFontOfSize: s.width];

        [[UIColor blackColor] setFill];

        [[NSString stringWithFormat: @"%d,%d", tilex, tiley] drawInRect: [self rectForMapRect: mapRect] withFont: f];
    }

    UIGraphicsPopContext();
}


- (void) requestFinished: (ASIHTTPRequest *) tileRequest
{
    NSValue* mapRectValue =  [tileRequest.userInfo objectForKey: @"mapRect"];
    MKMapRect mapRect;  [mapRectValue getValue: &mapRect];

    NSValue *zoomScaleValue = [tileRequest.userInfo objectForKey:@"zoomScale"];
    MKZoomScale zoomScale; [zoomScaleValue getValue: &zoomScale];

    NSLog( @"requestFinished: %d, %d, %lf", 
          [[tileRequest.userInfo objectForKey:@"tilex"] intValue], 
          [[tileRequest.userInfo objectForKey:@"tiley"] intValue], 
          zoomScale  );

    [self setNeedsDisplayInMapRect: mapRect zoomScale: zoomScale];
}

EDIT: 我猜想这一问题可能的话题。

最佳回答

我的问题与这里描述的问题非常相似。 在我的意见中,I cann t 转录了理想的行为(载于

- (BOOL)canDrawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale {
    NSLog(@"This should trace forever");

    [self setNeedsDisplayInMapRect:mapRect zoomScale:zoomScale];
    return NO;
}

或更接近我的原法典:

- (BOOL)canDrawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale {
    NSLog(@"This should trace forever");

    [SomeAsynchronousRequestWithCompletionHandler:^{
        [self setNeedsDisplayInMapRect:mapRect zoomScale:zoomScale];
    }];
    return NO;
}

在这两起案件中,setNeedsDisplayInMapRect:zoomScale:从未被打过一次。

当我开始运行setNeedsDisplayInMapRect:zoomScale:时,情况发生了变化。

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

    dispatch_queue_t queue = dispatch_get_current_queue();

    NSLog(@"This should trace forever");

    dispatch_async(queue, ^{
        [self setNeedsDisplayInMapRect:mapRect zoomScale:zoomScale];
    });

    return NO;
}

或者从事繁重的工作包括:

- (BOOL)canDrawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale {
    NSLog(@"This should trace forever");

    dispatch_queue_t queue = dispatch_get_current_queue();

    [SomeAsynchronousRequestWithCompletionHandler:^{
        dispatch_async(queue, ^{
            [self setNeedsDisplayInMapRect:mapRect zoomScale:zoomScale];
        });
    }];
    return NO;
}

采用发送方式——我可以看到。 我的原始问题也完全消失。

LATER UPDATE: 目前,我用发送“植被——主要——频率”来打电话setNeedsDisplayInMapRect:zoomScale:

- (BOOL)canDrawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale {
    NSLog(@"This should trace forever");

    [SomeAsynchronousRequestWithCompletionHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            [self setNeedsDisplayInMapRect:mapRect zoomScale:zoomScale];
        });
    }];
    return NO;
}
问题回答

以上答案对我来说并不可行。 从安全记录台的印刷版一中,我可以看到,尽管喷洒了烟雾中的植被——目前——频率(频率),并且储存起来供日后使用。 至少在IPad 4.3 Simulator一案中,我没有试图使用该装置。

My solution was less satisfactory and more error prone solution of wait x time before calling.

-(void)setNeedsDisplay:(WebRequest*)webRequest
{  
   [webRequest retain];
   dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.25 * NSEC_PER_SEC), dispatch_get_main_queue(), 
   ^{
      [webRequest autorelease];
      [delegate setNeedsDisplayInMapRect:webRequest.request.requestedMapRect 
                              zoomScale:webRequest.request.requestedScale];
   });     
}




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...