我正在尝试使用 和 为模态呈现的视图控制器创建自UIViewControllerTransitioningDelegate
定义UIViewControllerAnimatedTransitioning
转换UIPresentationController
。
在我的呈现视图控制器中,我实现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 的文档和几个教程实现了所有内容,但由于某种原因,它根本无法按预期工作。关于这里可能出现的问题有什么建议吗?