Skip to content

Instantly share code, notes, and snippets.

@0xlitf
Last active December 5, 2015 04:21
Show Gist options
  • Save 0xlitf/f871ff1ea56279620949 to your computer and use it in GitHub Desktop.
Save 0xlitf/f871ff1ea56279620949 to your computer and use it in GitHub Desktop.
panGesture
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureHandler:)];
[panGesture setMinimumNumberOfTouches:1];
[self.currentlistPageController.listPageView.planTableView addGestureRecognizer:panGesture];
- (void)panGestureHandler:(UIPanGestureRecognizer *)sender {
static double transitionOriginX;
static double transitionOriginY;
static double noticeViewY;
static double planTableViewY;
static double weatherViewY;
static double backgroundWeatherViewY;
typedef NS_ENUM (NSUInteger, PanDirection) {
NoDirection,
XDirection,
YDirection,
};
static PanDirection dir;
if (sender.state == UIGestureRecognizerStateBegan) {
dir = NoDirection;
transitionOriginX = [sender translationInView:self].x;
transitionOriginY = [sender translationInView:self].y;
noticeViewY = self.currentlistPageController.listPageView.planTableView.noticeView.y;
weatherViewY = self.currentlistPageController.listPageView.planTableView.weatherView.y;
planTableViewY = self.currentlistPageController.listPageView.planTableView.y;
backgroundWeatherViewY = self.currentlistPageController.listPageView.backgroundWeatherView.y;
}
if (sender.state == UIGestureRecognizerStateChanged) {
CGPoint translation = [sender translationInView:self];
double translationX = translation.x;
double translationY = translation.y;
if (dir == NoDirection) {
if (ABS(translationX - transitionOriginX) < ABS(translationY - transitionOriginY)) {
dir = YDirection;
}
else{
dir = XDirection;
}
}
if (dir == XDirection) {
// NSLog(@"XDirection");
}
if (dir == YDirection) {
// NSLog(@"YDirection");
double globalAlpha = 1 - ABS(self.currentlistPageController.listPageView.planTableView.y - planTableViewY)/100;
if (self.currentlistPageController.listPageView.planTableView.y - planTableViewY > 0) {
self.currentlistPageController.listPageView.planTableView.alpha = globalAlpha;
[self viewController].navigationController.navigationBar.alpha = globalAlpha;
self.currentlistPageController.listPageView.backgroundWeatherView.alpha = 1 - globalAlpha;
}
self.currentlistPageController.listPageView.planTableView.weatherView.alpha = globalAlpha;
self.currentlistPageController.listPageView.planTableView.y += translationY/2;
self.currentlistPageController.listPageView.planTableView.weatherView.y -= translationY/3;
self.currentlistPageController.listPageView.backgroundWeatherView.y -= translationY/6;
}
[sender setTranslation:CGPointZero inView:self];
}
if (sender.state == UIGestureRecognizerStateEnded) {
dir = NoDirection;
[UIView animateWithDuration:0.3 animations:^{
self.currentlistPageController.listPageView.planTableView.noticeView.y = noticeViewY;
self.currentlistPageController.listPageView.planTableView.weatherView.y = weatherViewY;
self.currentlistPageController.listPageView.backgroundWeatherView.y = backgroundWeatherViewY;
self.currentlistPageController.listPageView.planTableView.y = planTableViewY;
self.currentlistPageController.listPageView.planTableView.alpha = 1;
self.currentlistPageController.listPageView.planTableView.weatherView.alpha =1;
self.currentlistPageController.listPageView.planTableView.noticeView.alpha =1;
[self viewController].navigationController.navigationBar.alpha = 1;
self.currentlistPageController.listPageView.backgroundWeatherView.alpha = 0;
if (self.currentlistPageController.listPageView.planTableView.noticeView.y - noticeViewY <= 0) {
self.currentlistPageController.listPageView.backgroundWeatherView.alpha = 0;
}
} completion:^(BOOL finished) {
}];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment