문제

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