Skip to content

Commit

Permalink
Merge pull request #177 from life360/Issue174_PageAppeared
Browse files Browse the repository at this point in the history
Fix #174 - pageAppeared Delegate Callback
  • Loading branch information
ealeksandrov authored Jul 19, 2016
2 parents 0614ff1 + 52f7cdd commit e1b86ab
Showing 2 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions EAIntroView/EAIntroView.h
Original file line number Diff line number Diff line change
@@ -83,4 +83,7 @@ typedef NS_ENUM(NSUInteger, EAViewAlignment) {
- (void)setCurrentPageIndex:(NSUInteger)currentPageIndex;
- (void)setCurrentPageIndex:(NSUInteger)currentPageIndex animated:(BOOL)animated;


- (void)scrollToPageForIndex:(NSUInteger)newPageIndex animated:(BOOL)animated;

@end
16 changes: 14 additions & 2 deletions EAIntroView/EAIntroView.m
Original file line number Diff line number Diff line change
@@ -1007,7 +1007,17 @@ - (void)setCurrentPageIndex:(NSUInteger)currentPageIndex animated:(BOOL)animated

_currentPageIndex = currentPageIndex;

CGFloat offset = currentPageIndex * self.scrollView.frame.size.width;
[self scrollToPageForIndex:currentPageIndex animated:animated];
}

- (void)scrollToPageForIndex:(NSUInteger)newPageIndex animated:(BOOL)animated
{
if(![self pageForIndex:newPageIndex]) {
NSLog(@"Wrong newPageIndex received: %ld",(long)newPageIndex);
return;
}

CGFloat offset = newPageIndex * self.scrollView.frame.size.width;
CGRect pageRect = { .origin.x = offset, .origin.y = 0.0, .size.width = self.scrollView.frame.size.width, .size.height = self.scrollView.frame.size.height };
[self.scrollView scrollRectToVisible:pageRect animated:animated];

@@ -1023,7 +1033,9 @@ - (IBAction)goToNext:(id)sender {
if(self.currentPageIndex + 1 >= [self.pages count]) {
[self hideWithFadeOutDuration:0.3];
} else {
[self setCurrentPageIndex:self.currentPageIndex + 1 animated:YES];
// Just scroll to the new page.
// After scrolling ends, we call -checkIndexForScrollView:, which itself sets the new currentPageIndex.
[self scrollToPageForIndex:self.currentPageIndex + 1 animated:YES];
}
}

0 comments on commit e1b86ab

Please sign in to comment.