我正在尝试进行自定义过渡,例如"Match"。而且我希望这种转换发生在从表视图(符合UIViewControllerTransitionDelegate)单元到视图控制器的过程中。 这是tableView:didSelectRowAt:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
selectedFrame = cell.frame
performSegue(withIdentifier: "toDetails", sender: nil)
}
animationController:presented:presenting:source:
func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return CustomPresentTransition(originRect: selectedFrame)
}
在准备segue时,我设置了过渡代理。还有CustomPresentTransition:
class CustomPresentTransition: NSObject, UIViewControllerAnimatedTransitioning{
private let originRect: CGRect
init(originRect: CGRect) {
self.originRect = originRect
}
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return 2.0
}
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
guard let fromVC = transitionContext.viewController(forKey: .from),
let toVC = transitionContext.viewController(forKey: .to)
else{
return
}
let containerView = transitionContext.containerView
toVC.view.alpha = 0
containerView.addSubview(toVC.view)
UIView.animate(withDuration: transitionDuration(using: transitionContext), animations: {
})
}
}
我的问题是,应在UIView.animate中添加什么以创建该效果?在tableView:didSelectRowAt:中像这样传递单元格的框架是否正确?