Here is my problem: I've implemented a calendar in week mode, navigation between weeks is done using a UIPageViewController
in pagecurl mode (quite similar to the standard calendar of the iPad). Everything works well except when user aborts the page navigation.
So if the calendar is showing the current week and user pan with the finger to show next week but then aborts the gesture and he doesn't turn the page, the datasource will still display the next week instead of staying at the current week.
I tried using the method
- (void)pageViewController:(UIPageViewController *)pageViewController
didFinishAnimating:(BOOL)finished
previousViewControllers:(NSArray*)previousViewControllers
transitionCompleted:(BOOL)completed
and detecting when pangesture is aborted and then manually reset the previous viewcontroller but the result is not good at all.
Here is my code for the datasource and delegate methods
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
viewControllerBeforeViewController:(UIViewController *)viewController
{
if (_pageIsAnimating) {
return nil;
}
[[MCalendarManager sharedCalendar] previousWeek];
MCalendarContentViewController * contentViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"CalendarContentViewController"];
return contentViewController;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
viewControllerAfterViewController:(UIViewController *)viewController
{
if (_pageIsAnimating) {
return nil;
}
[[MCalendarManager sharedCalendar] nextWeek];
MCalendarContentViewController * contentViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"CalendarContentViewController"];
return contentViewController;
}
- (void)pageViewController:(UIPageViewController *)pageViewController willTransitionToViewControllers:(NSArray *)pendingViewControllers
{
_pageIsAnimating = YES;
}
- (void)pageViewController:(UIPageViewController *)pageViewController
didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers
transitionCompleted:(BOOL)completed
{
if (completed || finished) { // Turn is either finished or aborted
_pageIsAnimating = NO;
}
if (finished && !completed) {//Turn is aborted
//Do something here for not changing the viewcontroller
}
}
Does anyone has an idea how to solve this?
Thanks in advance.
Regards
Do something here for not changing the viewcontroller
? – danypata May 14 '13 at 21:08[[MCalendarManager sharedCalendar] previousWeek];
and[[MCalendarManager sharedCalendar] nextWeek];
methods are called because if a gesture is aborted and the animation is not completed, one of these methods is already called and in case the animation is aborted you should call the opposite method that was first called, so ifnextWeek
is called then you have to callpreviousWeek
and vice versa. – danypata May 16 '13 at 8:44Do something
part. – danypata May 16 '13 at 9:32