From 11e268e9b0881576b55b98dd4343831c7f07cb0a Mon Sep 17 00:00:00 2001 From: Nenad Ostojic Date: Wed, 2 May 2018 14:13:51 +0700 Subject: [PATCH] Handle orientation change, prevent delegate methods called and scrolling, otherwise UI gets messed up and scrolling delegates get called --- .../EMPageViewController.swift | 2 +- .../Greetings-ObjC/RootViewController.m | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/EMPageViewController/EMPageViewController.swift b/EMPageViewController/EMPageViewController.swift index a5e3ae9..c38592e 100644 --- a/EMPageViewController/EMPageViewController.swift +++ b/EMPageViewController/EMPageViewController.swift @@ -170,7 +170,7 @@ open class EMPageViewController: UIViewController, UIScrollViewDelegate { /// The direction the page controller is scrolling towards. open private(set) var navigationDirection: EMPageViewControllerNavigationDirection? - private var adjustingContentOffset = false // Flag used to prevent isScrolling delegate when shifting scrollView + public var adjustingContentOffset = false // Flag used to prevent isScrolling delegate when shifting scrollView private var loadNewAdjoiningViewControllersOnFinish = false private var didFinishScrollingCompletionHandler: ((_ transitionSuccessful: Bool) -> Void)? private var transitionAnimated = false // Used for accurate view appearance messages diff --git a/Examples/Greetings-ObjC/Greetings-ObjC/RootViewController.m b/Examples/Greetings-ObjC/Greetings-ObjC/RootViewController.m index 172a83a..ad366fd 100644 --- a/Examples/Greetings-ObjC/Greetings-ObjC/RootViewController.m +++ b/Examples/Greetings-ObjC/Greetings-ObjC/RootViewController.m @@ -188,5 +188,26 @@ - (void)em_pageViewController:(EMPageViewController *)pageViewController didFini } +- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id )coordinator { + [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; + // Code here will execute before the rotation begins. + // Equivalent to placing it in the deprecated method -[willRotateToInterfaceOrientation:duration:] + + // Disable scrolling in our swipe navigation to prevent layout issues. + [self.pageViewController.scrollView setScrollEnabled:NO]; + self.pageViewController.adjustingContentOffset = YES; + NSLog(@"ROTATING WILL START"); + [coordinator animateAlongsideTransition:^(id context) { + + } completion:^(id context) { + // Code here will execute after the rotation has finished. + // Equivalent to placing it in the deprecated method -[didRotateFromInterfaceOrientation:] + + // Enable scrolling once rotating finishes so we can use swipe navigation. + [self.pageViewController.scrollView setScrollEnabled:YES]; + self.pageViewController.adjustingContentOffset = NO; + NSLog(@"ROTATING FINISHED "); + }]; +} @end