Frage

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.

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top