3
我要让像iOS主屏幕上的文件夹设置动画的访问框架,我怎么也得知道的“文件夹”的最终位置的框架:在自定义动画toView对象
我使用自定义的过渡,这里的动画文件的代码:
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))
。
我已经按照this教程中,斯威夫特
所以写我的代码,我怎么能正确地访问属性?
我想访问'toViewC.containerView.frame',这是“文件夹”的矩形,正如你可以看到我的截图一样。我已经删除了转换,但它不工作... – ale00
哦,对不起!我误读了。等一下,我会编辑我的答案 – jrturton
但是,如果我发送'false'到'completeTransition'我回到我的第一个视图 – ale00