Came across this error when trying to do adapt some animations into Swift3 syntax.
UIView.animate(withDuration: duration, delay: 0.0, usingSpringWithDamping: 0.5,
initialSpringVelocity: 0.8, options: [] , animations: {
fromView.transform = offScreenLeft
toView.transform = CGAffineTransformIdentity
}, completion: { finished in
transitionContext.completeTransition(true)
})
and got this:
'CGAffineTransformIdentity' is unavailable in Swift
It’s used to check if a view’s transform is the identity transform. To change a UIView’s position, a translate matrix is applied to the transform matrix. This will change the values tx and ty values of the transform matrix. CGAffineTransform’s have a function translateBy (x:y:) and an initializer CGAffineTransform (translationX: , y: )
This is great for cases in which you’d like to execute specific code only for a specific iOS version. When navigating through Swift APIs you’ll often run into the @available attribute. We’ve just covered the #attribute which is similar but just a bit different. The shortest answer to describe its difference:
CGAffineTransform’s have a function translateBy (x:y:) and an initializer CGAffineTransform (translationX: , y: ) This function creates an affine transform matrix translating the current transform with the provided values.
The shortest answer to describe its difference: @available is used to mark the availability for a class or method #available is used to only execute a piece of code for specific platforms and/or versions We can demonstrate this by marking a class or method as available since iOS 14: @available( iOS 14, *) final class NewAppIntroduction { // .. }
Found this link which suggested that "The global constant was moved into a static property, and the Swift 3 migrator, as you've discovered, failed to correct for that. " and that you can simply change the code to :
toView.transform = CGAffineTransform.identity
EDIT
or even simpler:
toView.transform = .identity
Hope this helps somebody.
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