首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >自定义iOS 7交互式流行动画在动画后变为空白

自定义iOS 7交互式流行动画在动画后变为空白
EN

Stack Overflow用户
提问于 2014-03-31 19:44:54
回答 2查看 2.4K关注 0票数 2

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

  • 我用animationControllerForOperation把视图推得很好
  • 我为交互式的流行手势添加了边缘手势识别器。
  • 我使用了UIPercentDrivenInteractiveTransition子类和来自WWDC 2013 218 -使用视图控制器的自定义转换的集成代码。
  • 看起来它错误地删除了fromViewController,但我不知道为什么。
  • 这些步骤是:
代码语言:javascript
复制
1. Interactive pop starts
2. Finger is lifted after a short distance - red screenshot
3. The view animates back a short distance.
4. Red view is removed (I think) - black screenshot.

完整的代码在GitHub上,但是这里有两个部分我想是很重要的。

手势委托

代码语言:javascript
复制
- (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协议

代码语言:javascript
复制
- (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];
    }];
}

有人知道为什么屏幕是空白的吗?或者谁能给我指一些样本代码。苹果似乎没有任何使用百分比驱动的交互转换的示例代码。

EN

回答 2

Stack Overflow用户

发布于 2014-04-01 21:03:41

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

代码语言:javascript
复制
[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邮政

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

代码语言:javascript
复制
// self is a UIPercentDrivenInteractiveTransition
self.completionSpeed = 0.99;
票数 4
EN

Stack Overflow用户

发布于 2014-03-31 21:15:41

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

此链接用于交互式过渡。非常有用。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22770779

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档