Created
August 30, 2012 17:39
-
-
Save pmilosev/3534773 to your computer and use it in GitHub Desktop.
UINavigationController animation issues fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface NavigationController : UINavigationController <UINavigationControllerDelegate> { | |
NSMutableArray *animatingControllers; | |
} | |
@end | |
@implementation NavigationController | |
- (id)init | |
{ | |
self = [super init]; | |
if (self) { | |
animatingControllers = [NSMutableArray array]; | |
} | |
return self; | |
} | |
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated | |
{ | |
if (animated) { | |
[animatingControllers addObject:viewController]; | |
} | |
} | |
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated | |
{ | |
if (animated) { | |
[animatingControllers removeObject:viewController]; | |
} | |
} | |
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated | |
{ | |
if ([animatingControllers count] == 0) { | |
return [super pushViewController:viewController animated:animated]; | |
} | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
[self pushViewController:viewController animated:animated]; | |
}); | |
} | |
- (UIViewController *)popViewControllerAnimated:(BOOL)animated | |
{ | |
if ([animatingControllers count] == 0) { | |
return [super popViewControllerAnimated:animated]; | |
} | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
[self popViewControllerAnimated:animated]; | |
}); | |
return [self topViewController]; | |
} | |
- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated | |
{ | |
if ([animatingControllers count] == 0) { | |
return [super popToRootViewControllerAnimated:animated]; | |
} | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
[self popToRootViewControllerAnimated:animated]; | |
}); | |
NSArray *vcs = [self viewControllers]; | |
return [vcs subarrayWithRange:NSMakeRange(1, [vcs count] - 1)]; | |
} | |
- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated | |
{ | |
if ([animatingControllers count] == 0) { | |
return [super popToViewController:viewController animated:animated]; | |
} | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
[self popToViewController:viewController animated:animated]; | |
}); | |
NSArray *vcs = [self viewControllers]; | |
NSUInteger index = [vcs indexOfObject:viewController]; | |
index = index == NSNotFound ? [vcs count] : index; | |
return [vcs subarrayWithRange:NSMakeRange(index + 1, [vcs count] - index - 1)]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment