将ViewController缩小到圆形过渡-迅速

时间:2019-06-10 22:02:17

标签: ios swift core-animation cabasicanimation catransaction

我正在尝试按照该项目中的示例创建扩展/收缩视图控制器过渡。在我的情况下,所呈现的视图控制器将具有与按钮本身相同的背景色,因此,该动画本质上只是按钮扩展而覆盖了整个屏幕而从未消失。

enter image description here

https://github.com/AladinWay/TransitionButton

我将按钮放置在屏幕的右下角,并使用以下功能设法将其扩展:

private func expand(completion:(()->Void)?, revertDelay: TimeInterval) {

    let expandAnim = CABasicAnimation(keyPath: "transform.scale")
    let expandScale = (UIScreen.main.bounds.size.height/self.frame.size.height)*2
    expandAnim.fromValue            = 1.0
    expandAnim.toValue              = max(expandScale,26.0)
    expandAnim.timingFunction       = expandCurve
    expandAnim.duration             = 0.3
    expandAnim.fillMode             = .forwards
    expandAnim.isRemovedOnCompletion  = false

    CATransaction.setCompletionBlock {
        completion?()
        // We return to original state after a delay to give opportunity to custom transition
        DispatchQueue.main.asyncAfter(deadline: .now() + revertDelay) {
            self.setOriginalState(completion: nil)
            self.layer.removeAllAnimations() // make sure we remove all animation
        }
    }

    layer.add(expandAnim, forKey: expandAnim.keyPath)

    CATransaction.commit()
}

现在,我正在尝试创建用于消除视图控制器的动画,该动画将实质上反转初始动画并将整个屏幕缩小到屏幕底部的圆形按钮。我不确定如何修改上面的代码来扭转这种情况。

1 个答案:

答案 0 :(得分:0)

除了切换pm2fromValue之外,您可以尝试使用完全相同的块。

toValue