【问题标题】:Understanding CATransform3DRotate / CATransform3DMakeRotation了解 CATransform3DRotate / CATransform3DMakeRotation
【发布时间】:2016-02-17 01:45:35
【问题描述】:

我正在尝试了解如何像这样为我的UIView 创建深度感知:

我试过这段代码:

var rotationWithPerspective = CATransform3DIdentity;
rotationWithPerspective.m34 = -1.0/500.0/2/2
rotationWithPerspective = CATransform3DRotate(rotationWithPerspective, 22.5, 0, 1, 0);
preview.layer.transform = rotationWithPerspective

产生透视。然而,它出于某种原因翻转视图。

1) 如何避免转换后的“翻转”?

2) 变换产生的“透视深度”是否与每个给定的UIView 相同,还是取决于UIView 的大小等?

谢谢!

【问题讨论】:

    标签: ios swift object calayer catransform3drotate


    【解决方案1】:

    CATransform3DRotate 需要弧度而不是度数。你旋转了 22.5 弧度,相当于 1200 度。这可能就是您的图像反转的原因。你可能想用这个:

    let radians = 22.5 * M_PI / 180
    rotationWithPerspective = CATransform3DRotate(rotationWithPerspective, radians, 0, 1, 0);
    

    【讨论】:

    • 谢谢凯尔!顺便说一句,你对我的第二个问题有答案吗?它是“全局视角”值还是每个 UIView?
    【解决方案2】:

    对于 2)

    • 每个 UIView。
    • 如果你想应用到子层,你可以使用 sublayerTransform。 例如。 preview.layer.sublayerTransform = rotationWithPerspective

    您可以在 Nick Lockwood 的 iOS Core Animation - Advanced Techniques 中阅读更多相关信息。希望有所帮助。

    【讨论】:

    • 我想要 SWIFT 的那本书!它仅针对 Objective-C 发布:[
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-07
    • 1970-01-01
    相关资源
    最近更新 更多