Привет всем, я анимирую отображение 2 UIViewController внутри UIContainerView. Для представления контроллеров представления я реализовал этот метод
#pragma mark - Animation Controller
-(void)moveViewControllerFrom:(UIViewController *)currentViewController toViewController:(UIViewController *)nextViewController {
CGFloat widthVC = self.containerView.frame.size.width;
CGFloat heightVC = self.containerView.frame.size.height;
if (currentViewController == nextViewController) return;
if (_isNextViewController) {
nextViewController.view.frame = CGRectMake(widthVC, 0, widthVC, heightVC);
[self addChildViewController:nextViewController];
[currentViewController willMoveToParentViewController:nil];
[self transitionFromViewController:currentViewController toViewController:nextViewController duration:.4 options:0 animations:^{
nextViewController.view.frame = currentViewController.view.frame;
currentViewController.view.frame = CGRectMake(0 - widthVC, 0, widthVC, heightVC);
}
completion:^(BOOL finished) {
[currentViewController removeFromParentViewController];
[nextViewController didMoveToParentViewController:self];
}];
}
else {
nextViewController.view.frame = CGRectMake(0 -widthVC, 0, widthVC, heightVC);
[self addChildViewController:nextViewController];
[currentViewController willMoveToParentViewController:nil];
[self transitionFromViewController:currentViewController toViewController:nextViewController duration:.4 options:0 animations:^{
nextViewController.view.frame = currentViewController.view.frame;
currentViewController.view.frame = CGRectMake(widthVC, 0, widthVC, heightVC);
}
completion:^(BOOL finished) {
[currentViewController removeFromParentViewController];
[currentViewController didMoveToParentViewController:self];
}];
}
}
Теперь у меня возникла проблема, когда я быстро нажимаю кнопки «вперед» и «назад» (те, которые я использую для представления нового контроллера представления или для возврата к предыдущему контроллеру представления). Мое приложение сбой и консоль возвращает мне эту ошибку:
*** Завершение работы приложения из-за необработанного исключения «NSInvalidArgumentException», причина: «Контроллеры дочернего представления и должны иметь общий родительский контроллер представления при вызове -[UIViewController transitionFromViewController:toViewController:duration:options:animations:completion:]»
может кто-нибудь помочь мне понять, где я ошибаюсь в своем коде?