CATransform3DMakeRotation 和阴影

发布于 2024-10-06 08:50:57 字数 144 浏览 1 评论 0原文

我正在创建翻转动画库。

简而言之,我创建了 CALayer 并使用 CoreAnimation 的 CATransform3DMakeRotation 旋转它。

问题是 - 有没有办法为该场景添加阴影?无需使用 OpenGL 重写整个代码:)

I'm creating the flip animation library.

In two words, I create the CALayer and rotate it using CoreAnimation's CATransform3DMakeRotation.

The question is – is there a way to add a shadow to that scene? Without rewriting the whole code with OpenGL :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

溺孤伤于心 2024-10-13 08:50:57

看看 CAGradientLayer。我目前正在使用它在类似的情况下添加阴影。可能在性能方面代价高昂(仍需检查),但看起来相当令人信服。

CAGradientLayer 作为子图层添加到图层中,并为其不透明度设置动画。您可能需要稍微调整一下渐变停止点和颜色才能使其正确。

Have a look at CAGradientLayer. I am currently using it to add shadows in a similar situation. May be costly performance-wise (still have to check that), but looks quite convincing.

Add CAGradientLayer as sublayer(s) to your layers and animate its opacity. You may have to play around a little with the gradient stops and colors to get them right.

顾北清歌寒 2024-10-13 08:50:57

我不确定OpenGL,但你检查过CATransform3D

添加到

#define DEGREES_TO_RADIANS(d) (d * M_PI / 180)

.pch文件中,

CATransform3D myTransform = CATransform3DIdentity;
myTransform.m34 = 1.0 / -500;
myTransform = CATransform3DRotate(myTransform, DEGREES_TO_RADIANS(90), 0.0f, 0.0f, 1.0f);
myView.layer.transform = myTransform;

你可以继续在这里改变角度DEGREES_TO_RADIANS(90)

这里您可以向 myView 添加阴影。

I am not sure about OpenGL but have you checked CATransform3D

Add

#define DEGREES_TO_RADIANS(d) (d * M_PI / 180)

in .pch file

CATransform3D myTransform = CATransform3DIdentity;
myTransform.m34 = 1.0 / -500;
myTransform = CATransform3DRotate(myTransform, DEGREES_TO_RADIANS(90), 0.0f, 0.0f, 1.0f);
myView.layer.transform = myTransform;

you can go on changing the angle here DEGREES_TO_RADIANS(90)

Here you can add shadow to myView.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文