I am trying to make a UIImageView move when I tap a button. I have set a UIIAction to start an NSTimer. When tap the button, the character(UIImageView) moves fine. When I tap the same button again, the character speeds up and so forth so eventually he is moving a billion mph. How do I solve this? Here is the code:
-(void)animateCharRight:(NSTimer *)theTimer
{
float speed;
if (speed > 10.0f)
{
speed = 10.0f;
}
else
{
speed = 10.0f;
}
CGRect rect = [character frame];
rect.origin.x += speed;
[character setFrame:rect];
}
Also, when you press the opposite button after you already pressed one it bugs up because there is no cancelation of the other timer. How do I do that?
How do I access the key up event? I cant seem to find it.
Sounds like you might be starting a new timer on each button tap. So after 2 taps you now have 2 timers, each of which will call
-animateCharRight:to move your view 10, for a total of 20. More taps, faster, and so on. Is that what’s going on?