gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 04:32:13 25 4
gpt4 key购买 nike

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

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

    1. 交互式弹出窗口开始
    2. 手指在短距离后抬起 - 红色屏幕截图
    3. View 以动画方式返回一小段距离。
    4. 红色 View 已被删除(我认为) - 黑色屏幕截图。

enter image description here

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 似乎没有任何使用百分比驱动的交互进行交互转换的示例代码。

最佳答案

第一个问题是我复制的 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 .

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

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

关于ios - 自定义 iOS 7 交互式流行动画在动画后变为空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22770779/

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