Question

I'm trying to move an NSImageView while key is being pressed. Right now I have a boolean value that gets assigned true when keyDown is called, and false when keyUp is called. How could I animate an NSImageView to be moving while key is down?

For example, an image should move to the left while the left-arrow key is pressed.

Thanks in advance.

Was it helpful?

Solution

I would start a repeating NSTimer in your keyDown method, and in the timer's selector method just subtract a certain amount from the image view's frame.origin.x. In the keyUp method, you would invalidate the timer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top