我正在尝试为一个矩形实现模态垂直滑动的动画。然而,当我尝试编译代码时,我会得到以下错误:“Swift 4表达式类型“@value CGRect”在没有更多上下文的情况下是模棱两可的”。我已经将问题隔离到传递给CGRect init值的参数上,但根据苹果的iOS文档,这些参数应该足以指定我需要动画化的“frame”视图。
这是我的代码:
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
guard
let fromView = transitionContext.viewController(forKey: .from),
let toView = transitionContext.viewController(forKey: .to)
else {
return
}
let containerView = transitionContext.containerView
containerView.insertSubview((toView.view)!, belowSubview: (fromView.view)!)
let toFrame = transitionContext.finalFrame(for: toView)
let screenBounds = UIScreen.main.bounds
let bottomLeftCorner = CGPoint(x: 0, y: screenBounds.height)
let finalFrameForVC = CGRect(origin: bottomLeftCorner, size: screenBounds.size)
UIView.animate(withDuration: 2, delay: 1,
options: [], (using: transitionContext.finalFrame(for: fromView)),
animations: {
fromView.view.frame = finalFrameForVC
},
completion: { _ in
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
})
}