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

Fix for didPageToViewController providing incorrect or null UIViewController #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion MNPageViewController/MNPageViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@

- (void)mn_pageViewController:(MNPageViewController *)pageViewController willPageToViewController:(UIViewController *)viewController withRatio:(CGFloat)ratio;

@end
@end
21 changes: 6 additions & 15 deletions MNPageViewController/MNPageViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ @interface MNPageViewController() <MNQueuingScrollViewDelegate>

- (void)initializeChildControllers;
- (void)layoutControllers;
- (void)didPage;
- (void)didPageTo: (UIViewController *)viewController;
- (void)setNeedsRatioReset;
- (void)setNeedsRatioUpdate;

Expand All @@ -47,7 +47,7 @@ - (void)viewDidLoad {
self.initialized = NO;

if (self.viewController) {
CGRect bounds = self.view.bounds;
bounds = self.view.bounds;
bounds.origin.x = bounds.size.width;

[self.viewController willMoveToParentViewController:self];
Expand Down Expand Up @@ -170,18 +170,9 @@ - (void)layoutControllers {
self.scrollView.contentInset = UIEdgeInsetsMake(0.f, self.leftInset, 0.f, self.rightInset);
}

- (void)didPage {
UIViewController *visibleController = nil;
for (UIViewController *controller in self.childViewControllers) {
CGPoint point = [self.scrollView convertPoint:controller.view.frame.origin toView:self.view];

if (point.x == 0.f) {
visibleController = controller;
}
}

- (void)didPageTo: (UIViewController *)viewController {
if (self.delegate && [self.delegate respondsToSelector:@selector(mn_pageViewController:didPageToViewController:)]) {
[self.delegate mn_pageViewController:self didPageToViewController:visibleController];
[self.delegate mn_pageViewController:self didPageToViewController:viewController];
}
}

Expand Down Expand Up @@ -318,7 +309,7 @@ - (void)queuingScrollViewDidPageForward:(UIScrollView *)scrollView {
self.scrollView.contentInset = UIEdgeInsetsMake(0.f, self.leftInset, 0.f, self.rightInset);
}

[self didPage];
[self didPageTo:nextViewController];
}

- (void)queuingScrollViewDidPageBackward:(UIScrollView *)scrollView {
Expand Down Expand Up @@ -367,7 +358,7 @@ - (void)queuingScrollViewDidPageBackward:(UIScrollView *)scrollView {
self.scrollView.contentInset = UIEdgeInsetsMake(0.f, self.leftInset, 0.f, self.rightInset);
}

[self didPage];
[self didPageTo:nextViewController];
}

@end