Skip to content

Instantly share code, notes, and snippets.

@tatsuro-ueda
Created August 11, 2012 11:03
Show Gist options
  • Save tatsuro-ueda/3323831 to your computer and use it in GitHub Desktop.
Save tatsuro-ueda/3323831 to your computer and use it in GitHub Desktop.
【performSelector】ボタンを押し続けるとイメージが動き、離すと動きが止まる、には
##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.
![ss](http://farm8.staticflickr.com/7264/7758110866_f2d3a47f04_o.png)
- (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