I am trying to implement a animation for a rectangle to perform modal vertical swipe.However, when I try to compile the code I get the following error "Swift 4 Expression type '@value CGRect' is ambiguous without more context". I have isolated the issue to the arguments that is being passed to the CGRect init value, but according the Apple's iOS documentation these parameters should be enough to specify the 'frame' view that I need to animate.
Here is my code:
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)
})
}
I had the same error when I tried to multiply view.frame.height by a Double. If you are doing any math on screenBounds properties, make sure the types match.
My problem was that I was trying to perform an operation between a CGFloat variable and Double variable.
Fix: Convert the Double variable to CGFloat. Check your variable types.
I hope it helps! :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With