Skip to content

Instantly share code, notes, and snippets.

@sajoku
Created September 23, 2013 13:48
Show Gist options
  • Save sajoku/6670639 to your computer and use it in GitHub Desktop.
Save sajoku/6670639 to your computer and use it in GitHub Desktop.
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