Created
September 23, 2013 13:48
-
-
Save sajoku/6670639 to your computer and use it in GitHub Desktop.
Stolen from https://github.com/dbottillo/SlideOutNavigationRubyMotion/blob/master/app/controllers/menu_view_controller.rb
Pan Gesture recognizer. (slide view up and down)
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
| def viewDidLoad | |
| panGesture = UIPanGestureRecognizer.alloc.initWithTarget(self, action: "pan:") | |
| panGesture.delegate = self | |
| modal_view.addGestureRecognizer(panGesture) | |
| end | |
| def pan(gesture) | |
| piece = gesture.view | |
| adjustAnchorPointForGestureRecognizer(gesture) | |
| if (gesture.state == UIGestureRecognizerStateBegan || gesture.state == UIGestureRecognizerStateChanged) then | |
| translation = gesture.translationInView(piece.superview) | |
| x = piece.center.x + translation.x | |
| y = piece.center.y + translation.y | |
| # Some dimension to play with bounds.. This could be something like App.bounds.size.width (or height) | |
| #if x > -217.0 | |
| # x = -217.0 | |
| #end | |
| #if x < 290.0 | |
| # x = 290.0 | |
| #end | |
| #if y < 53.0 | |
| # puts 'y == ' + y.to_s | |
| # y = 53.0 | |
| #end | |
| #if y > 468.0 | |
| # puts 'y > 468 == ' + y.to_s | |
| # y = 468.00 | |
| #end | |
| piece.setCenter(CGPointMake(x,y)) | |
| gesture.setTranslation(CGPointZero, inView:piece.superview) | |
| else | |
| slideThenHide if gesture.state == UIGestureRecognizerStateEnded | |
| end | |
| end | |
| def slideThenHide | |
| #Add some code to slide th view down and make it transparent. | |
| end | |
| def adjustAnchorPointForGestureRecognizer(gestureRecognizer) | |
| if (gestureRecognizer.state == UIGestureRecognizerStateBegan) then | |
| piece = gestureRecognizer.view | |
| locationInView = gestureRecognizer.locationInView(piece) | |
| locationInSuperView = gestureRecognizer.locationInView(piece.superview) | |
| x = locationInView.x / piece.bounds.size.width | |
| y = locationInView.y / piece.bounds.size.height | |
| piece.layer.anchorPoint = CGPointMake(x,y) | |
| piece.center = locationInSuperView | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment