首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >UIViewPropertyAnimator AutoLayout完成问题

UIViewPropertyAnimator AutoLayout完成问题
EN

Stack Overflow用户
提问于 2018-07-24 03:15:20
回答 2查看 908关注 0票数 0

我使用三个函数来结合平移手势识别器来处理动画。

代码语言:javascript
复制
private var runningAnimations = [UIViewPropertyAnimator]()

private func startInteractiveTransition(gestureRecognizer: UIPanGestureRecognizer, state: ForegroundState, duration: TimeInterval) {

    if runningAnimations.isEmpty {
        animateTransitionIfNeeded(gestureRecognizer: gestureRecognizer, state: state, duration: duration)
    }

    for animator in runningAnimations {
        animator.pauseAnimation()
        animationProgressWhenInterrupted = animator.fractionComplete
    }
}

private func animateTransitionIfNeeded(gestureRecognizer: UIPanGestureRecognizer, state: ForegroundState, duration: TimeInterval) {

    guard runningAnimations.isEmpty else {
        return
    }

    let frameAnimator = UIViewPropertyAnimator(duration: duration, dampingRatio: 1) {

        switch state {
        case .expanded:
            // change frame
        case .collapsed:
            // change frame
        }
    }

    frameAnimator.isReversed = false

    frameAnimator.addCompletion { _ in
        print("remove all animations")
        self.runningAnimations.removeAll()
    }

    self.runningAnimations.append(frameAnimator)

    for animator in runningAnimations {
        animator.startAnimation()
    }
}

private func updateInteractiveTransition(gestureRecognizer: UIPanGestureRecognizer, fractionComplete: CGFloat) {

    if runningAnimations.isEmpty {
        print("empty")
    }
            for animator in runningAnimations {
        animator.fractionComplete = fractionComplete + animationProgressWhenInterrupted
    }
}

所以我相信这可能与swift处理内存的方式有关,或者与UIViewAnimating如何完成动画有关。

有什么建议吗?

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

https://stackoverflow.com/questions/51485746

复制
相关文章

相似问题

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