Chaque fois que l'utilisateur fait défiler la carte ou effectue un zoom avant/arrière, cette méthode est appelée instantanément. Je veux retarder l'appel à cette méthode par disons 2 secondes. Est-il possible de faire ça?Retarder l'appel à la méthode déléguée - mapView: regionDidChangeAnimated:
3
A
Répondre
4
Vous pouvez mettre en œuvre cette méthode comme ceci:
-(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];
}
Puis, quelque part dans la même classe:
-(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
}
Bien sûr, si vous n'avez pas besoin l'un de ces arguments (soit mapView
ou animated
), vous pourriez rendre cela considérablement plus simple en passant seulement celui dont vous aviez besoin.
Si vous ne pouvez pas modifier le code de votre MKMapViewDelegate
, vous pourriez peut-être faire quelque chose de similaire avec la méthode swizzling, bien que vous obtenez vraiment aki.
0
Vous pouvez envoyer un message différé avec performSelector:withObject:afterDelay:
ou l'une de ses méthodes associées.
remercie l'homme pour l'aide – Nanz