【问题标题】:Custom iOS 7 Interactive Pop Animation goes blank after animating自定义 iOS 7 交互式弹出动画在动画后变为空白
【发布时间】:2014-05-11 08:03:01
【问题描述】:

我正在使用新的 iOS 7 自定义转换 API 重新创建 UINavigationController Push 动画。

  • 我使用animationControllerForOperation 可以很好地推送和弹出视图
  • 我为交互式弹出手势添加了边缘手势识别器。
  • 我使用了UIPercentDrivenInteractiveTransition 子类和来自WWDC 2013 218 - Custom Transitions Using View Controllers 的集成代码
  • 好像是误删了fromViewController,不知道为什么。
  • 步骤如下:

    1. 交互式流行音乐开始
    2. 短距离后抬起手指 - 红色截图
    3. 视图动画返回一小段距离。
    4. 红色视图被移除(我认为) - 黑色屏幕截图。

The full code is on GitHub,但这里有两部分我认为很重要。

Gesture delegate

- (void)didSwipeBack:(UIScreenEdgePanGestureRecognizer *)edgePanGestureRecognizer {

    if (state == UIGestureRecognizerStateBegan) {
        self.isInteractive = YES;
        [self.parentNavigationController popViewControllerAnimated:YES];
    }

    if (!self.isInteractive) return;

    switch (state)
    {
        case UIGestureRecognizerStateChanged: {
            // Calculate percentage ...
            [self updateInteractiveTransition:percentagePanned];
            break;
        }

        case UIGestureRecognizerStateCancelled:
        case UIGestureRecognizerStateEnded: {

            if (state != UIGestureRecognizerStateCancelled &&
                isPannedMoreThanHalfWay) {
                [self finishInteractiveTransition];
            } else {
                [self cancelInteractiveTransition];
            }

            self.isInteractive = NO;
            break;
        }
    }
}

UIViewControllerAnimatedTransitioning protocol

- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext
{
    // Grab views ...

    [[transitionContext containerView] addSubview:toViewController.view];

    // Calculate initial and final frames        

    toViewController.view.frame = initalToViewControllerFrame;
    fromViewController.view.frame = initialFromViewControllerFrame;

    [UIView animateWithDuration:RSTransitionVendorAnimationDuration delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{

        toViewController.view.frame = finalToViewControllerFrame;
        fromViewController.view.frame = finalFromViewControllerFrame;
    } completion:^(BOOL finished) {

        [transitionContext completeTransition:YES];
    }];
}

有人知道为什么屏幕是空白的吗?或者任何人都可以指出一些示例代码。 Apple 似乎没有任何使用百分比驱动交互的交互过渡示例代码。

【问题讨论】:

  • 为什么你现在弹出视图控制器UIGestureRecognizerStateBegan而不是UIGestureRecognizerStateEnded
  • @ismailgulek 这就是交互式过渡的工作原理。

标签: ios cocoa-touch uiviewcontroller uinavigationcontroller core-animation


【解决方案1】:

第一个问题是我复制的 Apple 示例代码中的一个错误。 completeTransition 方法应该有一个更智能的 BOOL 参数,如下所示:

[UIView animateWithDuration:RSTransitionVendorAnimationDuration delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{

        toViewController.view.frame = finalToViewControllerFrame;
        fromViewController.view.frame = finalFromViewControllerFrame;
    } completion:^(BOOL finished) {

        [transitionContext completeTransition:![transitionContext transitionWasCancelled]];
    }];

感谢@rounak 将我指向objc.io post

这又提出了与动画有关的另一个问题。动画将停止,呈现一个空白视图,然后它们继续。这几乎是一个 UIKit 错误。解决方法是将completionSpeed 设置为 0.99 而不是 1.0。默认值为 1.0,所以我想将其设置为此不会在他们的自定义设置器中产生一些副作用。

// self is a UIPercentDrivenInteractiveTransition
self.completionSpeed = 0.99;

【讨论】:

  • 哈,我没有发现你总是在 completeTransition 中发送 YES。很高兴您的问题得到了解决!
【解决方案2】:

我认为您不需要 UIPercentDrivenInteractiveTransition 子类。我只是创建了一个新的UIPercentDrivenInteractiveTransition 对象,持有对它的强引用并在interactionControllerForAnimationController 方法中返回它。

This link for interactive transitions 很有帮助。

【讨论】:

  • 感谢您的建议。我正在关注他们建议使用子类的 218 WWDC。我会把它当作一个普通的对象来试一试。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-20
  • 2018-05-29
相关资源
最近更新 更多