How do you find the current scale (zoom level) of a UIView?
How do you find the current scale (zoom level) of a UIView?
Using some math around CGAffineTransform transformation matrix you can calculate a scale. This also mentioned in Margaret's comment. Swift allows you to write a simple extension with a computed property:
extension CGAffineTransform {
var scale: Double {
return sqrt(Double(a * a + c * c))
}
}
So, later you can use by calling a scale directly on the CGAffineTransform, like this:
let someViewScale = someView.transform.scale