How to know the current scale of a UIView?

后端 未结 6 971
一整个雨季
一整个雨季 2020-12-16 12:16

How do you find the current scale (zoom level) of a UIView?

6条回答
  •  春和景丽
    2020-12-16 12:34

    If you're applying a scale transform to your view, that transform will be available (appropriately enough) through the transform property on UIView. According to the CGAffineTransform docs, scale transforms will have nonzero values at coordinates (1,1) and (2,2) in the transform matrix; you can therefore get your x- and y-scale factors by doing:

    CGFloat xScale = view.transform.a;
    CGFloat yScale = view.transform.d;
    

提交回复
热议问题