我正在创建一个iPad应用程序,并希望使用视图的当前大小更新用户。我过去的做法是计算CGAffineTransform的比例,然后将xScale乘以宽度(相关视图),将yScale乘以高度。我想继续这样做,但我不再做2d转换,并且我不确定使用哪个方程来从CATransform3D中提取比例信息。
你能帮上忙吗?
发布于 2011-08-22 12:15:22
要获得图层的当前比例,只需在图层上执行valueForKeyPath::
CGFloat currentScale = [[layer valueForKeyPath: @"transform.scale"] floatValue];其他密钥可以在Apples Core Animation Programming Guide中找到
发布于 2010-12-15 06:56:35
我不熟悉这个接口,但是CATransform3D看起来像一个常规的4x4变换矩阵,用于进行3D变换。
假设它只表示缩放、旋转和平移的组合,则可以通过计算左上角3x3的行或列的幅值来提取缩放因子,这取决于CATransform3D是行还是列的主调。
例如,如果它是行较多的,则x方向上的刻度是( m11 * m11 ) +( m12 * m12 )+( m13 * m13 )的平方根。Y和z标度同样是第二行和第三行的大小。
从CATransform3DMakeTranslation的文档中可以看出,CATransform3D确实是以行为主的。
发布于 2019-11-05 00:07:47
这是swift 4+的更新答案
guard let currentScaleX = view.layer.value(forKeyPath: "transform.scale.x") as? CGFloat {
return
}
print ("the scale x is \(currentScaleX)")
guard let currentScaleY = view.layer.value(forKeyPath: "transform.scale.y") as? CGFloat {
return
}
print ("the scale y is \(currentScaleY)")https://stackoverflow.com/questions/4444932
复制相似问题