【问题标题】:Suppress navigation push animation in a custom view controller transition在自定义视图控制器转换中抑制导航推送动画
【发布时间】:2013-09-30 22:37:43
【问题描述】:

我将 iOS 7 中引入的新自定义视图控制器转换与 UINavigationController 结合使用。我实现了

-navigationController:animationControllerForOperation:fromViewController:toViewController:

在我的UINavigationControllerDelegate 中,实现了UIViewControllerAnimatedTransitioning 协议,自定义转换效果很好。

但是,我想在推动视图控制器时阻止导航栏中的 shift 动画。有趣的是,弹出动画很好,导航项只是 alpha-faded 而不是移位。但是推送动画会从右侧移动导航项。

我通过用-setViewControllers:animated: 替换-pushViewController:animated: 并将新的视图控制器添加到viewControllers 数组中找到了部分解决方案。这会执行正确的 alpha 渐变动画 - 除了第一次将视图控制器推送到堆栈上。随后的弹出/推送都很好。

知道如何实现这种效果吗? Calendar.app 和 Photos.app 也实现了这一点,所以它应该是可能的(尽管它可能是使用集合视图时的特定行为)。

【问题讨论】:

  • 我不知道你这里是否还有问题,但我无法重现它。你能提供更多细节吗?当我使用 animationControllerForOperation 指定自定义过渡时,动画会以我期望的方式影响我的内容,并且导航栏会消失(对于推送和弹出)。
  • 它确实会褪色,但它也会产生移位动画。我会发布我的解决方法。

标签: iphone cocoa-touch uinavigationcontroller uikit ios7


【解决方案1】:

我编写了一个解决方法,从导航栏子视图中删除所有位置动画:

@implementation UIView (FTNavigationBar)

static CGFloat leftMargin = 8;

- (void)removePushAnimation {
    CAAnimation *animation = [self.layer animationForKey:@"position"];
    if (animation) {
        if ([animation isKindOfClass:CABasicAnimation.class] && ((CABasicAnimation*)animation).fromValue) {
            CGPoint point = [((CABasicAnimation*)animation).fromValue CGPointValue];
            CGFloat halfSuperWidth = [self superviewOfKind:FTNavigationBar.class].bounds.size.width / 2;
            if ((fabs(point.x - halfSuperWidth) < 2 && fabs(self.center.x - halfSuperWidth) > 2) || fabs(point.x - self.frame.size.width/2 - leftMargin) < 2) {
                self.layer.position = point;
            }
        }
        [self.layer removeAnimationForKey:@"position"];
    }
    for (UIView *subview in [self subviews]) {
        [subview removePushAnimation];
    }
}

@end

【讨论】:

    猜你喜欢
    • 2016-05-30
    • 2015-08-21
    • 2014-01-11
    • 1970-01-01
    • 2015-12-19
    • 1970-01-01
    • 1970-01-01
    • 2018-09-24
    • 1970-01-01
    相关资源
    最近更新 更多