【问题标题】:Issues using animateAlongsideTransition in presentationTransitionWillBegin在presentationTransitionWillBegin 中使用animateAlongsideTransition 的问题
【发布时间】:2016-06-14 11:38:59
【问题描述】:

我正在尝试使用 UIViewControllerTransitioningDelegateUIViewControllerAnimatedTransitioningUIPresentationController 为模态呈现的视图控制器创建自定义转换。

在我的呈现视图控制器中,我实现了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 的文档和几个教程实现了所有内容,但由于某种原因,它根本无法按预期工作。关于这里可能出现的问题有什么建议吗?

【问题讨论】:

    标签: ios objective-c uikit uipresentationcontroller


    【解决方案1】:

    我相信您想在演示时使用presentingViewControllertransitionCoordinator,在解雇时使用presentedViewConrollertransitionCoordinator。这就是为什么它适用于解雇但不适用于您当前实施的演示。

    【讨论】:

      猜你喜欢
      • 2016-09-06
      • 1970-01-01
      • 1970-01-01
      • 2015-03-19
      • 1970-01-01
      • 1970-01-01
      • 2014-06-11
      • 1970-01-01
      • 2011-02-09
      相关资源
      最近更新 更多