gpt4 book ai didi

ios - 动画并不总是从 UIViewControllerAnimatedTransitioning 中的 animateTransition 可见

转载 作者:行者123 更新时间:2023-11-28 19:58:56 25 4
gpt4 key购买 nike

我正在使用一些 UIViewController包含在 UINavigationController 中.

一个人会收到一个推送 segue来自UIButtonstoryboard 上, 然后使用调用的滑动手势将其关闭

popViewControllerAnimated

我正在使用 UINavigationControllerDelegate提供符合 UINavigationControllerDelegate 的自定义对象. animateTransition 的代码如下所示。

我的问题是,第一次运行时, View 会在呈现时显示动画,但之后每次都不会显示动画(它只是立即出现)。

有人能帮忙吗?

谢谢!

-(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {

//Get references to the view hierarchy
UIView *containerView = [transitionContext containerView];
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];


if (self.isPresenting) {

[containerView insertSubview:toViewController.view belowSubview:fromViewController.view];

[UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
fromViewController.view.transform = CGAffineTransformMakeTranslation(-1000, 0);
} completion:^(BOOL finished) {
[transitionContext completeTransition:YES];
}];

} else if (!self.isPresenting) {
//Add 'to' view to the hierarchy
[containerView insertSubview:toViewController.view belowSubview:fromViewController.view];

//Scale the 'from' view down until it disappears
[UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
//toViewController.view.transform = CGAffineTransformMakeScale(1.0, 1.0);
fromViewController.view.transform = CGAffineTransformMakeScale(0.01, 0.01);
} completion:^(BOOL finished) {
[transitionContext completeTransition:YES];
}];
}
}

最佳答案

升级到 iOS8 后,我遇到了一组类似的问题。需要检查的几件事:

  1. 确保在开始动画之前调用这些:

    [toViewController beginAppearanceTransition:YES animated:YES];
    [fromViewController beginAppearanceTransition:NO animated:YES];

  2. 然后在完成 block 中调用这些:

    [toViewController endAppearanceTransition];
    [fromViewController endAppearanceTransition];
    [transitionContext completeTransition:finished];

需要以上内容来确保在正确的时间调用 viewWillAppear: 和 viewWillDisappear:。

  1. 设置 modalPresentationStyle = UIModalPresentationFullScreen,而不是 UIModalPresentationCustom(其行为非常不同)。

希望这对您有所帮助。

干杯!

关于ios - 动画并不总是从 UIViewControllerAnimatedTransitioning 中的 animateTransition 可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25060943/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com