在核心图形中沿z轴向下移动图像 [英] Moving an image down the z-axis in core graphics

查看:43
本文介绍了在核心图形中沿z轴向下移动图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UIImageView,我想浮动到背景中.它会沿z轴移动并向中心会聚,这是您想像的一些远离您的运动.

I have an UIImageView i want to float off into the background. It should be shirking as it moves along the z-axis and converge towards the center as you'd image something moving away from you does.

我尝试了这段代码

theImageView.layer.transform = CATransform3DTranslate(theImageView.layer.transform,1,1, 
-100);

还有这个

theImageView.layer.transform = CATransform3DTranslate(theImageView.layer.transform,0, 0, 
-300);    

但是图像在完全相同的位置.核心图形中不可能出现这种情况吗?

But the image is in the exact same place. Is it not possible to this kind of thing in core graphics?

如果通过CATransform无法做到这一点,人们将如何处理?改用某种黑客手段进行扩展吗?

How are people handling this if its not possible through CATransform? Using some kind of hack with scaling instead?

非常感谢-代码

推荐答案

即使Core Animation在3D空间中工作,默认情况下它也不使用透视图.要创建透视变换,必须直接修改变换矩阵的成员:

Even though Core Animation works in 3D space, it does not use perspective by default. To create a perspective transform, you have to modify a member of the transformation matrix directly:

CATransform3D transform = CATransform3DIdentity;
transform.m34 = 1.0 / -2000;  // this value affects the "amount" of perspective

(请参见例如 http://watchingapple.com/2008/04/core-animation-3d-perspective/).

这篇关于在核心图形中沿z轴向下移动图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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