Skip to content

Instantly share code, notes, and snippets.

@Abban
Created March 4, 2013 18:01
Show Gist options
  • Select an option

  • Save Abban/5084145 to your computer and use it in GitHub Desktop.

Select an option

Save Abban/5084145 to your computer and use it in GitHub Desktop.
Gesture callback to convert a pan into seconds.
- (void)secondPan:(UIPanGestureRecognizer *)gesture
{
if ((gesture.state == UIGestureRecognizerStateChanged) ||
(gesture.state == UIGestureRecognizerStateEnded)){
CGPoint location = [gesture locationInView:gesture.view.superview];
int topBound = gesture.view.bounds.size.height / 2.0f;
float bottomBound = gesture.view.superview.bounds.size.height - topBound;
float position;
if(location.y <= topBound){
position = topBound;
}else if(location.y >= bottomBound){
position = bottomBound;
}else{
position = location.y;
}
gesture.view.center = CGPointMake(gesture.view.center.x, position);
self.secondsAmount.frame = CGRectMake(0, 0, self.minuteBounds.frame.size.width, position-topBound);
int time = (59 / (bottomBound - topBound)) * (position - topBound);
NSString *formattedTime = (time < 10) ? [NSString stringWithFormat:@"0%d",time] : [NSString stringWithFormat:@"%d",time];
self.seconds.text = formattedTime;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment