我想制作一个类似于iOS主屏幕文件夹的动画,并且需要知道“文件夹”的最终位置的帧数:
我正在使用自定义转换,以下是动画文件的代码:
class FolderAnimationController: NSObject, UIViewControllerAnimatedTransitioning {
let duration = 5.0
var presenting = true
func transitionDuration(_ transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return duration
}
func animateTransition(_ transitionContext: UIViewControllerContextTransitioning) {
let containerView = transitionContext.containerView()
let toViewC = transitionContext.viewController(forKey: UITransitionContextToViewControllerKey)! as! ProjectViewController
let fromViewC = transitionContext.viewController(forKey: UITransitionContextFromViewControllerKey)!as! ViewController
let cell : FolderCollectionViewCell = fromViewC.folderCollectionView.cellForItem(at: (fromViewC.folderCollectionView.indexPathsForSelectedItems()?.first!)!) as! FolderCollectionViewCell
let cellSnapshot: UIView = cell.snapshotView(afterScreenUpdates: false)!
let cellFrame = containerView.convert(cell.frame, from: cell.superview)
cellSnapshot.frame = cellFrame
cell.isHidden = true
toViewC.view.frame = transitionContext.finalFrame(for: toViewC)
toViewC.view.alpha = 0
containerView.addSubview(toViewC.view)
containerView.addSubview(cellSnapshot)
UIView.animate(withDuration: duration, animations: {
toViewC.view.alpha = 1.0
let finalFrame = containerView.convert(toViewC.containerView.frame, from: toViewC.view)
cellSnapshot.frame = finalFrame
}) { (_) in
cellSnapshot.removeFromSuperview()
transitionContext.completeTransition(true)
}
}
}
除了
let finalFrame = containerView.convert(toViewC.containerView.frame, from: toViewC.view)
这一行代码设置finalFrame
的值(这是一个CGRect变量)为(origin = (x = 0,y = 0),size = (width = 0,height = 0))
之外,其他都正确无误。我按照这篇教程进行编写,使用Swift语言。
那么,我该如何正确访问此属性呢?
toViewC.containerView.frame
,也就是“文件夹”的矩形框,正如您在截图中所看到的。我已经删除了转换,但它仍然无法工作... - alessionossacompleteTransition
发送false
,我会返回到我的第一个视图。 - alessionossa