Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip button fade #84

Merged
merged 2 commits into from
Sep 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Demo/Demo Files/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions Source/OnboardingViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
33 changes: 24 additions & 9 deletions Source/OnboardingViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
}
}


Expand Down