Created
March 4, 2013 18:01
-
-
Save Abban/5084145 to your computer and use it in GitHub Desktop.
Gesture callback to convert a pan into seconds.
This file contains hidden or 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
| - (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