简单的核心动画UIView的3D变换

时间:2013-03-12 23:24:18

标签: iphone ios core-animation

我正在尝试使用CA制作简单的部分翻转动画,但我遇到了透视问题。我尝试过:

    [UIView animateWithDuration:1.0 animations:^{
    self.someView.layer.anchorPoint = CGPointMake(0.5, 0);
    self.someView.layer.transform = CATransform3DMakeRotation(M_PI*0.6,1.0,0.0,0.0);
} completion:^(BOOL finished){
    // code to be executed when flip is completed
}];

如何获得这个好看的视角?

enter image description here

2 个答案:

答案 0 :(得分:29)

这样的事情可以做到:

CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
rotationAndPerspectiveTransform.m34 = 1.0 / -1000.0;
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, M_PI * 0.6, 1.0f, 0.0f, 0.0f);
[UIView animateWithDuration:1.0 animations:^{
    self.someView.layer.anchorPoint = CGPointMake(0.5, 0);
    self.someView.layer.transform = rotationAndPerspectiveTransform;
} completion:^(BOOL finished){
    // code to be executed when flip is completed
}];

答案 1 :(得分:1)

How do I apply a perspective transform to a UIView?

查看有问题的答案。

基本上你修改了矩阵的m34,它控制了多少物体缩小到背景中。

如果您更好奇,请查看: http://www.songho.ca/opengl/gl_projectionmatrix.html