Skip to content

Commit

Permalink
iOS 7 Bugfix for non-animated transitions
Browse files Browse the repository at this point in the history
  • Loading branch information
absolute-heike committed Nov 19, 2015
1 parent 5fcac42 commit 224d5c2
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions Pod/Classes/UIViewController+LVModalQueue.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ +(void)load
/**
* custom implementation of presentViewController. Creates a transition block, that can be queued for later in case a view controller is currently transitioning
*/
- (void)lv_queuePresentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion
- (void)lv_queuePresentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)animated completion:(void (^)(void))completion
{
[UIViewController lv_performTransition:^{
UIViewController *presenter = [self lv_topmostPresentedViewController];
Expand All @@ -64,25 +64,22 @@ - (void)lv_queuePresentViewController:(UIViewController *)viewControllerToPresen
if ([UIDevice currentDevice].systemVersion.floatValue < 8.0)
{
// because we swizzled the implementations, this will call the original implementation
[presenter lv_queuePresentViewController:viewControllerToPresent animated:flag completion:completion];
[presenter lv_queuePresentViewController:viewControllerToPresent animated:animated completion:completion];

[self.transitionCoordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context)
{
[UIViewController lv_transitionDidComplete];
}];
[UIViewController lv_subscribeForCompletionWithTransitioningCoordinator:presenter.transitionCoordinator isAnimated:animated];
}
else
{
// because we swizzled the implementations, this will call the original implementation
[presenter lv_queuePresentViewController:viewControllerToPresent animated:flag completion:[UIViewController lv_queueBlockWithCompletionBlock:completion animated:flag]];
[presenter lv_queuePresentViewController:viewControllerToPresent animated:animated completion:[UIViewController lv_queueBlockWithCompletionBlock:completion animated:animated]];
}
}];
}

/**
* custom implementation of dismissViewController. Creates a transition block, that can be queued for later in case a view controller is currently transitioning
*/
- (void)lv_queueDismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
- (void)lv_queueDismissViewControllerAnimated:(BOOL)animated completion:(void (^)(void))completion
{
[UIViewController lv_performTransition:^{
[UIViewController lv_transitionWillStart];
Expand All @@ -91,7 +88,7 @@ - (void)lv_queueDismissViewControllerAnimated:(BOOL)flag completion:(void (^)(vo
if (!self.presentingViewController && !self.presentedViewController)
{
// call the original dismiss method anyway, to let UIKit decide, wether to call the completion block or not.
[self lv_queueDismissViewControllerAnimated:flag completion:completion];
[self lv_queueDismissViewControllerAnimated:animated completion:completion];
[UIViewController lv_transitionDidComplete];

return;
Expand All @@ -101,17 +98,14 @@ - (void)lv_queueDismissViewControllerAnimated:(BOOL)flag completion:(void (^)(vo
if ([UIDevice currentDevice].systemVersion.floatValue < 8.0)
{
// because we swizzled the implementations, this will call the original implementation
[self lv_queueDismissViewControllerAnimated:flag completion:completion];
[self lv_queueDismissViewControllerAnimated:animated completion:completion];

[self.transitionCoordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context)
{
[UIViewController lv_transitionDidComplete];
}];
[UIViewController lv_subscribeForCompletionWithTransitioningCoordinator:self.transitionCoordinator isAnimated:animated];
}
else
{
// because we swizzled the implementations, this will call the original implementation
[self lv_queueDismissViewControllerAnimated:flag completion:[UIViewController lv_queueBlockWithCompletionBlock:completion animated:flag]];
[self lv_queueDismissViewControllerAnimated:animated completion:[UIViewController lv_queueBlockWithCompletionBlock:completion animated:animated]];
}
}];
}
Expand Down Expand Up @@ -207,6 +201,29 @@ + (void)lv_transitionDidComplete
};
}

/**
* Subscribes for the completion of a transitioningCoordinator
*
* @param transitioningCoordinator the transitioningCoordinator of the transition
* @param animated is the transition animated or not?
*
* @since <#version number#>
*/
+ (void)lv_subscribeForCompletionWithTransitioningCoordinator:(id<UIViewControllerTransitionCoordinator>)transitioningCoordinator isAnimated:(BOOL)animated
{
if (!animated || !transitioningCoordinator)
{
[UIViewController lv_transitionDidComplete];

return;
}

[transitioningCoordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context)
{
[UIViewController lv_transitionDidComplete];
}];
}


#pragma mark - Fetch top view controller

Expand Down

0 comments on commit 224d5c2

Please sign in to comment.