Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'CGAffineTransformIdentity' is unavailable in Swift

Tags:

xcode8

swift3

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

like image 874
AMAN77 Avatar asked Oct 12 '16 09:10

AMAN77


People also ask

How do I change a UIView’s position using cgaffinetransform?

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: )

When to use the @available attribute in Swift?

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:

What is translateby in cgaffinetransform?

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.

What is the difference between @available and @available in Swift?

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 { // .. }


1 Answers

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.

like image 50
AMAN77 Avatar answered Nov 23 '22 15:11

AMAN77