Whenever the user scrolls map or zooms in/out, this method gets called instantaneously. I want to delay the call to this method by say 2 secs. Is it possible to do that?
A:
You can send a delayed message with performSelector:withObject:afterDelay:
or one of its related methods.
NSResponder
2010-04-17 23:19:09
+1
A:
You could implement that method like this:
-(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
NSNumber *animatedNumber = [NSNumber numberWithBool:animated];
NSArray *args = [[NSArray alloc] initWithObjects:mapView,
animatedNumber,nil];
[self performSelector:@selector(delayedMapViewRegionDidChangeAnimated:)
withObject:args
afterDelay:2.0f];
[args release];
}
Then, somewhere in the same class:
-(void)delayedMapViewRegionDidChangeAnimated:(NSArray *)args
{
MKMapView *mapView = [args objectAtIndex:0];
BOOL animated = [[args objectAtIndex:1] boolValue];
// do what you would have done in mapView:regionDidChangeAnimated: here
}
Of course, if you don't need one of those arguments (either mapView
or animated
), you could make this considerably simpler by only passing the one you did need.
If you can't just edit the code for your MKMapViewDelegate
, perhaps you could do something similar with method swizzling, although then you're getting really hacky.
igul222
2010-04-17 23:43:46
thanks man for the help
Nanz
2010-04-22 13:22:34