CATransform3D-了解变换值 [英] CATransform3D - understanding the transform values

查看:89
本文介绍了CATransform3D-了解变换值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

图片显示了应用以下转换后的简单UIView:

The picture shows a simple UIView after applying the following transform:

- (CATransform3D) transformForOpenedMenu
{
  CATransform3D transform = CATransform3DIdentity;
  transform.m34 = -1.0 /450;
  transform = CATransform3DRotate(transform, D2R(40), 0, 1, 0);
  transform = CATransform3DTranslate(transform, 210, 150, -500);
  return transform;
}

我正在尝试用黑色突出显示的距离具有相等的长度。您能帮我理解值和计算背后的逻辑吗?

I'm trying to make the distances highlighted with black to have equal length. Could you please help me understand the logic behind the values and calculations?

干杯

外观就像删除3DTranslate一样使距离相等。我看到我可以使用图层的frame属性将旋转的视图重新定位到屏幕的左下角。尚不确定,但这实际上可能有效。

Looks like removing 3DTranslate keeps distances equal. I see I can use layer's frame property to reposition rotated view to the bottom left of the screen. Not yet sure, but this might actually work.

推荐答案

好的,所以最终解决我问题的是这个:

OK, so what eventually solved my question is this:


  • 在Y轴上进行3D变换以像门一样摆动视图 transform = CATransform3DRotate(transform,D2R(40),0,1,0);

  • 在图层上设置Z锚点,将其移回 targetView.layer.anchorPointZ = 850;

  • 调整图层位置,以使该视图稍微位于父视图的左下方:

  • 3D transform on Y axis to swing the view like a door transform = CATransform3DRotate(transform, D2R(40), 0, 1, 0);
  • set Z anchor point on a layer, to move it back targetView.layer.anchorPointZ = 850;
  • adjust layer position so that the view is located slightly to the bottom left of the parent view:

newPosition.x + = 135 * positionDirection;
newPosition.y + = 70 * positionDirection;

此序列会调整 CATransform3DTranslate 的位置,并保持摆动效果不失真。

This sequence adjusts position without CATransform3DTranslate and keeps the 'swinged' effect not distorted.

谢谢大家!

这篇关于CATransform3D-了解变换值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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