如何知道 UIView 的当前比例? [英] How to know the current scale of a UIView?

查看:20
本文介绍了如何知道 UIView 的当前比例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何找到 UIView 的当前比例(缩放级别)?

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

推荐答案

如果您对视图应用比例变换,则该变换将通过 转换 属性 在 UIView 上.根据 CGAffineTransform 文档,缩放变换将在变换矩阵中的坐标 (1,1) 和 (2,2) 处具有非零值;因此,您可以通过以下方式获得 x 和 y 比例因子:

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;

这篇关于如何知道 UIView 的当前比例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆