swiftcatransform3d

setting transform on UIView in Swift?


In objective-C I could do:

CGAffineTransform myTransform = CGAffineTransformMake(1, 0, 0, -1, 0, 200.0);
self.myView.transform = myTransform;

So, I am trying t do the same thing in Swift:

let myTransform:CGAffineTransform  = CGAffineTransformMake(1.0, 0.0, 0.0, -1.0, 0.0, 200.0)
self.myView.transform = myTransform

It tells me that UIView does not have a member named "transform"

How can I achieve this in swift?


Solution

  • I think you have declared the myView property as UIView?. Thats why the compiler complains about it. You can declare it as UIView, but then you have to assign it in your class' constructor, or use !, like following:

    self.myView!.transform = myTransform