简体   繁体   English

应用透视变换而不旋转

[英]Apply a perspective transform without rotating

I have been trying to perform a perspective transform on a UIView. 我一直在尝试对UIView执行透视变换。 I have been working from this example . 我一直在这个例子中工作。

However, that example applies a rotation on the view as well as a perspective change. 但是,该示例在视图上应用旋转以及透视更改。 Is there a way to change the perspective of the view with no rotation? 有没有办法在没有旋转的情况下改变视图的视角? Something that might look like this: 可能看起来像这样的东西:

在此输入图像描述

I have been trying to remove the rotation, but when I do the perspective transform does not get applied. 我一直试图去除旋转,但是当我做透视变换时不会应用。 I can't find any examples out there that deal with just changing the perspective. 我找不到任何只是改变观点的例子。 Thanks in advance. 提前致谢。

Just adding to David's answer: To get an output as in your image you have to rotate the view around the x-axis (the horizontal axis) so that the upper edge of the view rectangle appears "further away" from the viewer than the lower edge, eg 只需添加大卫的答案:要获得图像中的输出,您必须围绕x轴(水平轴)旋转视图,以便视图矩形的上边缘显示“远离观察者”而不是下方边缘,例如

CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
rotationAndPerspectiveTransform.m34 = 1.0 / -200;
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, 45.0f * M_PI / 180.0f, 1.0f, 0.0f, 0.0f);
layer.transform = rotationAndPerspectiveTransform;

Perspective won't be visible without any rotation relative to your view point. 没有相对于您的视点的任何旋转,透视将不可见。 The perspective does still get applied even when you don't rotate but it won't be very visible. 即使您不旋转,但仍然会应用透视,但它不会非常明显。

One other transform that shows perspective is translating along Z which makes the view look like it is being scaled. 另一个显示透视的变换是沿Z平移,这使得视图看起来像是缩放的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将透视变换应用于 UIView? - How do I apply a perspective transform to a UIView? 可可:是否可以使用“透视变换”? - Cocoa: is a “perspective transform” available? 如何在图像上应用Perspective 3d Transform并将该图像保存在文档目录中 - How to apply Perspective 3d Transform on image and save that image in document directory 在OpenGL / GLKit中使用透视原点进行透视变换 - Perspective transform with perspective origin in OpenGL/GLKit 如何在不使用-webkit-transform的情况下在iOS上应用css转换? - How to apply css transform on iOS without using -webkit-transform? 将带有透视变换的 UIView 转换为 UIImage - Converting UIView with perspective transform to UIImage UICollectionViewCell透视变换在出现/消失 - UICollectionViewCell Perspective Transform on Appear/Disappear 使用OpenCV在iOS中进行透视变换+裁剪 - Perspective Transform + Crop in iOS with OpenCV Swift iOS-使用CATransform3D .m34属性更改Swift中的视角时,应用其他更改进行转换 - Swift iOS -Apply additional changes to transform when using CATransform3D .m34 property to change perspective in Swift 带阴影旋转不带阴影旋转的 UIButton - UIButton with shadow rotating without shadow rotating
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM