Search code examples
iphoneiostouches

How to wait for touch input on iOS


I am running an animation but I don't want to start the animation until the user touches the screen. I thought of using a loop but that takes a lot of overhead and I couldn't even get it to work for this.

I am aware of the touchesEnded and touchedBegin methods but I am not sure how to use them in this manner.

Thanks in advance.


Solution

  • you can just use touchesBegan / Ended in your viewcontroller code and it will trigger when you touch the screen(touchesBegan) or lift your finger off(touches)

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    //start animation
    }
    OR
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    //startAnimation
    }