Skip to content

Instantly share code, notes, and snippets.

@kenshin03
Created May 10, 2013 00:36
Show Gist options
  • Save kenshin03/5551666 to your computer and use it in GitHub Desktop.
Save kenshin03/5551666 to your computer and use it in GitHub Desktop.
PSHMenuGestureRecognizer
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch * touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self.view];
UIView * menuView = [self.view viewWithTag:kPSHMenuViewControllerMenuButtonViewTag];
if (CGRectContainsPoint(menuView.frame, touchPoint)){
[self setState:UIGestureRecognizerStateBegan];
self.menuViewBeingMoved = menuView;
}else{
[self setState:UIGestureRecognizerStateFailed];
self.menuViewBeingMoved = nil;
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch * touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self.view];
CGRect menuViewFrame = self.menuViewBeingMoved.frame;
menuViewFrame.origin = CGPointMake(touchPoint.x-44.0f, touchPoint.y-44.0f);
[UIView animateWithDuration:0.1 delay:0.1 options:UIViewAnimationOptionCurveEaseIn animations:^{
self.menuViewBeingMoved.frame = menuViewFrame;
} completion:^(BOOL finished) {
// none
}];
[self setState:UIGestureRecognizerStateChanged];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[self setState:UIGestureRecognizerStateEnded];
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
[self setState:UIGestureRecognizerStateEnded];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment