PhilCai
2015-10-27 11:07:36 +08:00
- (void)movelMenu:(UIGestureRecognizer *)sender {
[[[(UITapGestureRecognizer *)sender view] layer] removeAllAnimations];
CGPoint translatedPoint =
[(UIPanGestureRecognizer *)sender translationInView:self.view];
CGPoint velocity =
[(UIPanGestureRecognizer *)sender velocityInView:self.view];
if (sender.state == UIGestureRecognizerStateEnded) {
if (velocity.x > 0) {
NSLog(@"gesture went right");
} else {
NSLog(@"gesture went left");
}
if (!self.showMenu) {
[self moveMenuToOriginalPosition];
} else {
if (self.showingSlideMenu) {
[self moveMenuRight];
}
}
}
if (sender.state == UIGestureRecognizerStateChanged) {
self.showMenu = sender.view.center.x > 0;
[sender view].center = CGPointMake(
[sender view].center.x + translatedPoint.x, [sender view].center.y);
[(UIPanGestureRecognizer *)sender setTranslation:CGPointZero
inView:self.view];
self.preVelocity = velocity;
if (sender.view.frame.origin.x >= 0) {
sender.view.frame = CGRectMake(0, sender.view.frame.origin.y,
sender.view.frame.size.width,
sender.view.frame.size.height);
}
}
}