【问题标题】:How to avoid clipping when animating transform in viewController transitionAnimation在viewController过渡动画中动画变换时如何避免剪辑
【发布时间】:2020-03-17 06:20:19
【问题描述】:

我有一个自定义动画 viewController 转换的问题。

我有一个 collectionView (fromView),当一个单元格被选中时,它会增长到 fullSize (toView)。

除了底部单元格之外,它工作得很好,它们在动画到中心时被裁剪。

我试图改变 containerView 的框架以获得额外的空间来避免裁剪,但它弄乱了其中 viewcontrollers 的位置。

这是转换的相关代码和发现问题的草图。

非常感谢。

实际行为: 预期的:

// originFrame 由 fromView 中选中的单元格定义 var originFrame = CGRect.zero

    func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {


        guard let toView = transitionContext.view(forKey: .to),
                    let fromView = transitionContext.view(forKey: .from)
                    else { return }

        let finalFrame = toView.frame
        let growFactor = finalFrame.width / originFrame.width

        let centerDiffX = fromView.center.x-originFrame.midX
        let centerDiffY = fromView.center.y-originFrame.midY


        // Animate the transition.
        UIView.animate(
            withDuration: duration,
            delay:0.0,
            animations: {

                let scaleTransform = CGAffineTransform(scaleX: growFactor, y: growFactor)
                fromView.transform = CGAffineTransform(translationX: deltaX, y: deltaY).concatenating(scaleTransform)

                ...

【问题讨论】:

    标签: ios animation swift3 uicollectionviewcell


    【解决方案1】:

    制作collectionview的快照就可以了;)

    【讨论】:

      猜你喜欢
      • 2022-07-17
      • 2020-04-13
      • 2023-03-09
      • 2020-10-15
      • 2012-03-17
      • 1970-01-01
      • 2015-06-15
      • 2011-12-03
      • 1970-01-01
      相关资源
      最近更新 更多