Ios Swift-UIViewControllerAnimatedTransitioning未按预期使用Swift4进行转换

Ios Swift-UIViewControllerAnimatedTransitioning未按预期使用Swift4进行转换,ios,swift4,xcode9,Ios,Swift4,Xcode9,我今天刚用Swift4升级到XCode9。 我发现我的UIViewControllerAnimatedTransitioning不再像预期的那样工作了。 此动画的效果是fromView将缩小到0.95,toView将从右侧滑入。pop操作将反向执行。 但是现在当我点击导航栏的后退按钮时,toView的开始位置不正确。它显示一个原始大小toView,然后放大到1.05 下面是我如何实现过渡动画 // animate a change from one viewcontroller to anoth

我今天刚用Swift4升级到XCode9。 我发现我的
UIViewControllerAnimatedTransitioning
不再像预期的那样工作了。 此动画的效果是
fromView
将缩小到0.95,
toView
将从右侧滑入。
pop
操作将反向执行。 但是现在当我点击导航栏的后退按钮时,
toView
的开始位置不正确。它显示一个原始大小
toView
,然后放大到1.05

下面是我如何实现过渡动画

// animate a change from one viewcontroller to another
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
    // get reference to our fromView, toView and the container view that we should perform the transition in
    let container = transitionContext.containerView
    let fromView = transitionContext.view(forKey: UITransitionContextViewKey.from)!
    let toView = transitionContext.view(forKey: UITransitionContextViewKey.to)!

    // set up from 2D transforms that we'll use in the animation
    let offScreenRight = CGAffineTransform(translationX: container.frame.width, y: 0)
    let offScreenDepth = CGAffineTransform(scaleX: 0.95, y: 0.95)

    // start the toView to the right of the screen
    if( presenting ){
        toView.transform = offScreenRight

        container.addSubview(fromView)
        container.addSubview(toView)
    }
    else{
        toView.transform = offScreenDepth

        container.addSubview(toView)
        container.addSubview(fromView)
    }

    // get the duration of the animation
    // DON'T just type '0.5s' -- the reason why won't make sense until the next post
    // but for now it's important to just follow this approach
    let duration = self.transitionDuration(using: transitionContext)

    // perform the animation!
    // for this example, just slid both fromView and toView to the left at the same time
    // meaning fromView is pushed off the screen and toView slides into view
    // we also use the block animation usingSpringWithDamping for a little bounce

    UIView.animate(withDuration: duration, delay: 0.0, options: .curveEaseOut, animations: {

        if( self.presenting ){
            fromView.transform = offScreenDepth
        }
        else{
            fromView.transform = offScreenRight
        }

        toView.transform = .identity

    }, completion: { finished in

        transitionContext.completeTransition(!transitionContext.transitionWasCancelled)

    })
}
我在这个迁移指南页面中没有发现任何特别的内容。
如何使转换再次工作?

在设置任何其他内容之前,请尝试将
从视图
转换为
标识

// animate a change from one viewcontroller to another
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
    ...

    UIView.animate(withDuration: duration, delay: 0.0, options: .curveEaseOut, animations: {

        if( self.presenting ){
            fromView.transform = offScreenDepth
        }
        else{
            fromView.transform = offScreenRight
        }

        toView.transform = .identity

    }, completion: { finished in

        fromView.transform = .identity
        transitionContext.completeTransition(!transitionContext.transitionWasCancelled)

    })

    ....
}

这更可能是ios11问题,而不是swift 4问题。我不知道为什么会出现这个问题。不起作用。
转换的值似乎正确。问题在于显示。它确实从0.95变为1。但是它显示为从1到1.05的转换。好吧,我猜之前的转换与当前的发生了某种冲突。。虽然情况不应该是这样我过一会儿再看一看我找到了解决办法。只需将
从view.transform=.identity移动到
UIView.animate的完成块。谢谢你的提示。