Skip to content

Instantly share code, notes, and snippets.

@pmilosev
Created August 30, 2012 17:39
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save pmilosev/3534773 to your computer and use it in GitHub Desktop.
UINavigationController animation issues fix
@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