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

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

问题描述

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

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

推荐答案

如果您正在对视图应用缩放变换,则可以通过 transform property 在UIView上。根据 CGAffineTransform docs ,比例变换在变换矩阵中的坐标(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天全站免登陆