سؤال

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.

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top