diff --git a/Pod/Classes/JDFPeekabooCoordinator.h b/Pod/Classes/JDFPeekabooCoordinator.h index d428943..6c35b10 100644 --- a/Pod/Classes/JDFPeekabooCoordinator.h +++ b/Pod/Classes/JDFPeekabooCoordinator.h @@ -61,11 +61,21 @@ */ - (void)fullyExpandViews; +/** + * Returns all of the views to their default position. + */ +- (void)fullyExpandViewsAnimated:(BOOL)animated; + /** * Moves all of the views to their minimised position; */ - (void)fullyHideViews; +/** + * Moves all of the views to their minimised position; + */ +- (void)fullyHideViewsAnimated:(BOOL)animated; + #pragma mark - Enabling/Disabling diff --git a/Pod/Classes/JDFPeekabooCoordinator.m b/Pod/Classes/JDFPeekabooCoordinator.m index c241f58..8e610df 100644 --- a/Pod/Classes/JDFPeekabooCoordinator.m +++ b/Pod/Classes/JDFPeekabooCoordinator.m @@ -117,15 +117,40 @@ - (void)setBarsNeedDisplay - (void)fullyExpandViews { - [self animateTopViewToYPosition:self.topViewDefaultY]; - [self animateBottomViewToYPosition:(self.containingView.frame.size.height - self.bottomBarDefaultHeight)]; + [self fullyExpandViewsAnimated:NO]; +} + +- (void)fullyExpandViewsAnimated:(BOOL)animated +{ + void (^block)() = ^() { + [self animateTopViewToYPosition:self.topViewDefaultY]; + [self animateBottomViewToYPosition:(self.containingView.frame.size.height - self.bottomBarDefaultHeight)]; + }; + + if (!animated) { + [UIView performWithoutAnimation:block]; + } else { + block(); + } [self setBarsNeedDisplay]; } - (void)fullyHideViews { - [self animateTopViewToYPosition:[self topViewMinimisedY]]; - [self animateBottomViewToYPosition:[self bottomViewMinimisedY]]; + [self fullyHideViewsAnimated:NO]; +} + +- (void)fullyHideViewsAnimated:(BOOL)animated +{ + void (^block)() = ^() { + [self animateTopViewToYPosition:[self topViewMinimisedY]]; + [self animateBottomViewToYPosition:[self bottomViewMinimisedY]]; + }; + if (!animated) { + [UIView performWithoutAnimation:block]; + } else { + block(); + } [self setBarsNeedDisplay]; } @@ -240,7 +265,7 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView CGFloat topViewPercentageHidden = [self topViewPercentageHidden]; [self updateTopViewSubviews:(1 - topViewPercentageHidden)]; - + self.previousScrollViewYOffset = scrollOffset; } @@ -296,7 +321,7 @@ - (void)updateTopViewSubviews:(CGFloat)alpha } else if (alpha < 0.0f) { alpha = 0.0f; } - + for (UIView *view in self.topViewItems) { view.alpha = alpha; } @@ -320,8 +345,10 @@ - (void)animateTopViewToYPosition:(CGFloat)y frame.origin.y = y; [self.topView setFrame:frame]; [self updateTopViewSubviews:alpha]; - } completion:^(BOOL finished) { + [self setBarsNeedDisplay]; + } completion:^(BOOL finished) { + //[self setBarsNeedDisplay]; }]; } @@ -331,16 +358,16 @@ - (void)animateBottomViewToYPosition:(CGFloat)y CGRect frame = self.bottomView.frame; frame.origin.y = y; [self.bottomView setFrame:frame]; - } completion:^(BOOL finished) { [self setBarsNeedDisplay]; + } completion:^(BOOL finished) { + //[self setBarsNeedDisplay]; }]; } - (CGFloat)topViewPercentageHidden { - CGFloat statusBarHeight = [[UIApplication sharedApplication] statusBarFrame].size.height; CGRect frame = self.topView.frame; - CGFloat percentage = (self.topViewDefaultY - frame.origin.y - (self.topViewDefaultY - statusBarHeight)) / (frame.size.height - 1 - self.topViewMinimisedHeight); + CGFloat percentage = 1 - (frame.size.height + frame.origin.y - self.topViewMinimisedHeight) / (frame.size.height - self.topViewMinimisedHeight); return percentage; }