Swift version: 5.0
UIView subclass has a
transform property that lets you manipulate its size, position and rotation using something called an affine transform. This property is animatable, which means you can make a view smoothly double in size, or make it spin around, just by changing one value.
Here are some examples to get you started:
imageView.transform = CGAffineTransform(scaleX: 2, y: 2) imageView.transform = CGAffineTransform(translationX: -256, y: -256) imageView.transform = CGAffineTransform(rotationAngle: CGFloat.pi) imageView.transform = CGAffineTransform.identity
The first one makes an image view double in size, the second one makes it move up and left 256 points, the third one makes it spin around 180 degrees (the values are expressed in radians), and the fourth one sets the image view's transform back to "identity" – this means "reset."
SPONSOR Tired of wasting time debugging your Swift app? Instabug’s SDK is here to help you minimize your debugging time by providing you with complete device details, network logs, and reproduction steps with every bug report. All data is attached automatically. It only takes a line of code to setup. Get started for free.
Available from iOS 2.0 – see Hacking with Swift tutorial 15
Did this solution work for you? Please pass it on!
Other people are reading…
About the Swift Knowledge Base
This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions.