Created
August 11, 2012 11:03
-
-
Save tatsuro-ueda/3323831 to your computer and use it in GitHub Desktop.
【performSelector】ボタンを押し続けるとイメージが動き、離すと動きが止まる、には
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##Press and hold to make Image move | |
With below code, you have to push 3 seconds to move _imageView, and then the image begins moving, and when you release the button, the image stops. | |
 | |
- (IBAction)pushToMove:(id)sender { | |
[self performSelector:@selector(move) withObject:nil afterDelay:3.0]; | |
} | |
- (void)move | |
{ | |
_nt = [NSTimer scheduledTimerWithTimeInterval:0.1 | |
target:self | |
selector:@selector(goRight) | |
userInfo:nil | |
repeats:YES]; | |
} | |
- (void)goRight | |
{ | |
_imageView.frame = CGRectMake(_imageView.frame.origin.x + 10, _imageView.frame.origin.y, | |
_imageView.frame.size.width, _imageView.frame.size.height); | |
} | |
- (IBAction)stop | |
{ | |
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(move) object:nil]; | |
[_nt invalidate]; | |
} | |
I put this sample project to GitHub. You can download and just run it. | |
<https://github.com/weed/p120804_ImageMoveDuringPushButton> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment