同时透视和翻转 UIImageView
我正在尝试翻转并旋转 uiimageview 的透视,以获得类似反射的效果。首先我使用 CATransform3D 给出透视图,然后使用 CGAffineTransformMake 进行翻转。然而,我在第二次转换后失去了透视效果。我不知道如何使用 CATransform3D 来透视和翻转两者。 img 是第一张图像,img2 将是它的反射。
CALayer *layer = img.layer;
CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
rotationAndPerspectiveTransform.m34 = 1.0 / -600;
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, 30.0f * M_PI / 180.0f, 0.0f, 1.0f, 0.0f);
layer.transform = rotationAndPerspectiveTransform;
img2.transform = CGAffineTransformMake(
1, 0, 0, -1, 0, img2.bounds.size.height
);
I am trying to flip and give perspective rotate an uiimageview, in order to obtain an effect like reflection. first i give perspective using CATransform3D and then flip using CGAffineTransformMake. However i loose the perspective effect after the second trasnformation. and i couldn't figure out how to perspective and flip both using CATransform3D. img is the first image and img2 will be its reflection.
CALayer *layer = img.layer;
CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
rotationAndPerspectiveTransform.m34 = 1.0 / -600;
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, 30.0f * M_PI / 180.0f, 0.0f, 1.0f, 0.0f);
layer.transform = rotationAndPerspectiveTransform;
img2.transform = CGAffineTransformMake(
1, 0, 0, -1, 0, img2.bounds.size.height
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能够通过 4 个(可选 5 个)步骤完成此效果:
正常加载主图像。现在加载倒影,如下所示:
现在创建透视变换,如下所示:
最后,将反射移动到位:
可以选择添加渐变,使反射逐渐消失在图像中。
背景:
看起来像这样:
I was able to accomplish this effect in 4 (optionally 5) steps:
Load up the main image as normal. Now load up the reflection to be upside-down like so:
Now create the perspective transform like so:
Finally, move the reflection into place:
Optionally, add a gradient to make the reflection fade away into the
background:
It looks like this: