Я пытаюсь создать настраиваемый переход для модально представленного контроллера вида с использованием UIViewControllerTransitioningDelegate
, UIViewControllerAnimatedTransitioning
и UIPresentationController
.Проблемы с использованием animateAlongsideTransition в представленииTransitionWillBegin
В моем предлежащом контроллере представления я реализую UIViewControllerTransitioningDelegate
и имею следующие методы:
-(id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented
presentingController:(UIViewController *)presenting
sourceController:(UIViewController *)source {
return [[MyAnimationController alloc] initWithAnimationType:MyAnimationTypePresent];
}
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed {
return [[MyAnimationController alloc] initWithAnimationType:MyAnimationTypeDismiss];
}
- (UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented
presentingViewController:(UIViewController *)presenting
sourceViewController:(UIViewController *)source {
return [[MyPresentationController alloc] initWithPresentedViewController:presented presentingViewController:presenting];
}
Теперь в моем подклассе UIPresentationController
я добавляю вид затемнения под представленным контроллером представления и хочу исчезать его вместе с внешний переход.
- (void)presentationTransitionWillBegin {
self.dimmingView.alpha = 0.0f;
[self.containerView insertSubview:self.dimmingView atIndex:0];
[self.dimmingView autoPinEdgesToSuperviewEdges];
[self.presentedViewController.transitionCoordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
self.dimmingView.alpha = 1.0f;
}
completion:nil];
}
- (void)dismissalTransitionWillBegin {
[self.presentedViewController.transitionCoordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
self.dimmingView.alpha = 0.0f;
}
completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
[self.dimmingView removeFromSuperview]; }];
}
Интересно - и довольно сложно - дело в том, что презентация и увольнения анимации для моего представленного вида контроллера работы, как ожидается, и как это реализовано в MyAnimationController
. Что касается постепенного исчезновения изображения, то он работает только при отклонении представленного контроллера представления. Когда вы представляете его, затухание не анимируется вместе с переходом, а просто использует фиксированное количество времени. Я уверен, что я реализовал все в соответствии с документацией Apple и несколькими учебниками, но по какой-то причине он просто не будет работать так, как ожидалось. Любое предложение относительно того, что может быть здесь?