0

I have a crosshair on the iphone screen and when a pavilion (dot on map) moves under it i want to start zooming on the map. I all ready got the detection to work when a pavilion comes under the crosshair and the moment it is not under it anymore.

For now i post it in here in psuedo code:

- (void) checkForPavilionUnderCrosshair {

   if(new pavilion under crosshair) {
     // start zooming
   }
   else if(just left pavilion under crosshair){
     // stop zooming
   }
}

So what i need to do now is keep triggering:

mapView setZoom:(mapView.zoom+0.1) animated:NO];

And being able to stop that progress when the crosshair moves off the pavilion.

I did some searches on stackoverflow but the posts i found did not include stopping it for example. I have no experience with timing things in programs so could someone help me a litle by telling what i'm looking for?

I tried [self performSelector:@selector(zoomTest) withObject:self afterDelay:0.0];

If i keep touching the map and move my finger then it keeps checkForPavilionUnderCrosshair just like i want. But the perform selector get's fired after i stop touching the screen, so if i touch the screen for 20 seconds it fires 20 seconds to late.

Any workaround for that?

latonz
  • 1,601
  • 10
  • 21
clankill3r
  • 9,146
  • 20
  • 70
  • 126

1 Answers1

2

You can call [self performSelector:@selector(checkForPavilionUnderCrosshair) withObject:nil afterDelay:1.0] at the end of your method to have it called again after the specified time period. Note that the delay is in seconds.

If you want something more advanced, you can look at NSTimer over at the Apple docs, or see this SO question for an example and explanation.

If you decide to use the simple performSelector method, you can simply not call the method when you don't want to repeat anymore. If you choose to use NSTimer, call invalidate on the timer to stop it.

Community
  • 1
  • 1
Greg
  • 9,068
  • 6
  • 49
  • 91