我正在尝试使用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的文档和几个教程实现了所有内容,但由于某些原因它根本无法按预期工作。关于这里可能出现什么问题的任何建议?
答案 0 :(得分:1)
我认为您希望在演示文稿中使用presentingViewController
transitionCoordinator
,并在解雇时使用presentedViewConroller
transitionCoordinator
。这就是为什么它适用于解雇但不是当前实施的呈现方式。