据我所知,似乎插入 UINavigationController
背靠背动画在 iOS7 上造成了死锁。
我最初在 iOS6 上遇到崩溃并想出了以下解决方案:
UINavigationControllerDelegate
的navigationController:didShowViewController:animated:
所以本质上如果有 B 和 C View Controller 被推送,
navigationController:didShowViewController:animated:
将被调用 3 次;每次从 A 开始推送 View Controller 之后。显然,最后一次调用不会做任何事情,因为此时数组应该是空的。 请注意,这种方法在 iOS6 上运行良好。但是,这在 iOS7 中中断了。似乎当它尝试在第二次推送中设置动画时,应用程序卡住了。在深入挖掘之后,我想出了在委托(delegate)实现中以以下方式推送第二个 View Controller 的解决方案。
dispatch_async(dispatch_get_main_queue(), ^{
[navigationController pushViewController:viewController
animated:YES];
});
这似乎解决了这个问题,但我想知道是否有人经历过类似的事情并对到底发生了什么有更好的解释。
最佳答案
我不确定你遇到了什么问题。我创建了一个具有导航 Controller 和其他四个 Controller 的测试应用程序。第一个 Controller 有一个按钮可以推送到第二个 Controller ,即 FirstPushedViewController。在那个 Controller 中,我有这段代码来推送接下来的两个 Controller ,它在 iOS 7 中运行良好:
@interface FirstPushedViewController ()
@property (strong,nonatomic) NSMutableArray *vcs;
@end
@implementation FirstPushedViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationController.delegate = self;
UIViewController *orange = [self.storyboard instantiateViewControllerWithIdentifier:@"Orange"];
UIViewController *red = [self.storyboard instantiateViewControllerWithIdentifier:@"Red"];
self.vcs = [@[red,orange] mutableCopy];
}
-(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
if (self.vcs.count > 0) {
[self.navigationController pushViewController:self.vcs.lastObject animated:YES];
[self.vcs removeLastObject];
}
}
关于iOS7 UINavigationController pushViewController :animated back to back with animation locks up the main thread,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19714288/