From 2ffd43f4e93ba1ba563b8e3f6f81afba4691c20d Mon Sep 17 00:00:00 2001 From: Mike Amaral Date: Wed, 2 Sep 2015 17:03:06 -0400 Subject: [PATCH 1/2] Added property to OnboardingViewController to allow for automatically fading in and out the skip button when moving to or from the last page. --- Source/OnboardingViewController.h | 1 + Source/OnboardingViewController.m | 33 ++++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/Source/OnboardingViewController.h b/Source/OnboardingViewController.h index 36b1427..6e0bfe2 100644 --- a/Source/OnboardingViewController.h +++ b/Source/OnboardingViewController.h @@ -21,6 +21,7 @@ @property (nonatomic) BOOL shouldBlurBackground; @property (nonatomic) BOOL shouldFadeTransitions; @property (nonatomic) BOOL fadePageControlOnLastPage; +@property (nonatomic) BOOL fadeSkipButtonOnLastPage; // Skipping @property (nonatomic) BOOL allowSkipping; diff --git a/Source/OnboardingViewController.m b/Source/OnboardingViewController.m index fc49e25..1098099 100644 --- a/Source/OnboardingViewController.m +++ b/Source/OnboardingViewController.m @@ -75,6 +75,7 @@ - (instancetype)initWithContents:(NSArray *)contents { self.shouldBlurBackground = NO; self.shouldFadeTransitions = NO; self.fadePageControlOnLastPage = NO; + self.fadeSkipButtonOnLastPage = NO; self.swipingEnabled = YES; self.hidePageControl = NO; @@ -412,8 +413,9 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView { // calculate the percent complete of the transition of the current page given the // scrollview's offset and the width of the screen CGFloat percentComplete = fabs(scrollView.contentOffset.x - self.view.frame.size.width) / self.view.frame.size.width; + CGFloat percentCompleteInverse = 1.0 - percentComplete; - // these cases have some funk results given the way this method is called, like stuff + // these cases have some funky results given the way this method is called, like stuff // just disappearing, so we want to do nothing in these cases if (_upcomingPage == _currentPage || percentComplete == 0) { return; @@ -425,20 +427,33 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView { // set the current page's alpha to the difference between 100% and this percent value, // so we're 90% scrolling towards the next page, the current content's alpha sshould be 10% - [_currentPage updateAlphas:1.0 - percentComplete]; + [_currentPage updateAlphas:percentCompleteInverse]; + + // determine if we're transitioning to or from our last page + BOOL transitioningToLastPage = (_upcomingPage == self.viewControllers.lastObject); + BOOL transitioningFromLastPage = (_currentPage == self.viewControllers.lastObject) && (_upcomingPage == self.viewControllers[self.viewControllers.count - 2]); - // If we want to fade the page control on the last page... + // fade the page control to and from the last page if (self.fadePageControlOnLastPage) { - // If the upcoming page is the last object, fade the page control out as we scroll. - if (_upcomingPage == [self.viewControllers lastObject]) { - _pageControl.alpha = 1.0 - percentComplete; + if (transitioningToLastPage) { + _pageControl.alpha = percentCompleteInverse; } - - // Otherwise if we're on the last page and we're moving towards the second-to-last page, fade it back in. - else if ((_currentPage == [self.viewControllers lastObject]) && (_upcomingPage == self.viewControllers[self.viewControllers.count - 2])) { + + else if (transitioningFromLastPage) { _pageControl.alpha = percentComplete; } } + + // fade the skip button to and from the last page + if (self.fadeSkipButtonOnLastPage) { + if (transitioningToLastPage) { + _skipButton.alpha = percentCompleteInverse; + } + + else if (transitioningFromLastPage) { + _skipButton.alpha = percentComplete; + } + } } From 86e865c71e24d5ebf5bf12baf095e01b6002465e Mon Sep 17 00:00:00 2001 From: Mike Amaral Date: Wed, 2 Sep 2015 17:03:22 -0400 Subject: [PATCH 2/2] Added the new skip button fade to the first demo onboarding experience. --- Demo/Demo Files/AppDelegate.m | 1 + 1 file changed, 1 insertion(+) diff --git a/Demo/Demo Files/AppDelegate.m b/Demo/Demo Files/AppDelegate.m index 92c7a4c..bb21e2e 100644 --- a/Demo/Demo Files/AppDelegate.m +++ b/Demo/Demo Files/AppDelegate.m @@ -87,6 +87,7 @@ - (OnboardingViewController *)generateFirstDemoVC { OnboardingViewController *onboardingVC = [OnboardingViewController onboardWithBackgroundImage:[UIImage imageNamed:@"street"] contents:@[firstPage, secondPage, thirdPage]]; onboardingVC.shouldFadeTransitions = YES; onboardingVC.fadePageControlOnLastPage = YES; + onboardingVC.fadeSkipButtonOnLastPage = YES; // If you want to allow skipping the onboarding process, enable skipping and set a block to be executed // when the user hits the skip button.