Ios 设置UIView透视图的动画,使其向上/远离底部翻转一半

Ios 设置UIView透视图的动画,使其向上/远离底部翻转一半,ios,objective-c,cocoa-touch,uiview,Ios,Objective C,Cocoa Touch,Uiview,我有一个视图,我想翻转一下,就像这里的插图 我当前的解决方案: [UIView animateWithDuration:duration animations:^{ [someView.layer setAffineTransform:CGAffineTransformMakeScale(1, 0)]; }]; 此解决方案的问题在于,上边缘向下移动,而下边缘向上移动。我希望顶部边缘保

我有一个视图,我想翻转一下,就像这里的插图

我当前的解决方案:

[UIView animateWithDuration:duration
                 animations:^{
                     [someView.layer setAffineTransform:CGAffineTransformMakeScale(1, 0)];
                 }];
此解决方案的问题在于,上边缘向下移动,而下边缘向上移动。我希望顶部边缘保持不变,底部边缘向上/远离,如图所示

编辑:就像那些猫门一样,哈哈。将圆盘/方形曲面推离顶部的铰链

编辑2:解决方案

CGFloat someViewHeight = self.someView.frame.size.height;

CATransform3D baseTransform = CATransform3DIdentity;
baseTransform.m34 = - 1.0 / 200.0;
self.someView.layer.zPosition = self.view.frame.size.height * 0.5;
self.someView.layer.transform = baseTransform;

CATransform3D rotation = CATransform3DMakeRotation(- M_PI_2, 1.0, 0.0, 0.0);
CATransform3D firstTranslation = CATransform3DMakeTranslation(0.0, someViewHeight * 0.5, 0.0);
CATransform3D secondTranslation = CATransform3DMakeTranslation(0.0, - someViewHeight * 0.5, 0.0);

self.someView.layer.transform = CATransform3DConcat(CATransform3DConcat(firstTranslation, CATransform3DConcat(rotation, secondTranslation)), baseTransform);
花了一段时间,直到我发现
[UIView animateWithDuration::
会对透视图或其他东西进行动画处理,所以动画会缩小视图并做一些我无法解释的奇怪事情。现在我自己制作动画,每次只需改变角度。

你的意思是这样的:

    [UIView animateWithDuration:3.0 animations:^{
        [someView.layer setAffineTransform:
         CGAffineTransformConcat(CGAffineTransformMakeScale(1.0f, .0001f), CGAffineTransformMakeTranslation(.0f, someView.frame.size.height*-.5f))];
    }];
这只是解决了您描述的问题,要在图像上显示结果,您需要进行3D转换

在您的情况下,要进行3D变换,事情会变得相当棘手:

    CGFloat viewHeight = someView.frame.size.height; //needed later as this value will change because of transformation applied
    CATransform3D baseTransform = CATransform3DMakeTranslation(.0f, .0f, viewHeight*.5f); //put it towards user for rotation radius
    baseTransform.m34 = -1.0/200.0; //this will make the perspective effect
    someView.layer.zPosition = view.frame.size.height*.5f; //needed so the view isn't clipped
    someView.layer.transform = baseTransform; //set starting transform (no visual effect here)

    [UIView animateWithDuration:6.6 animations:^{
        someView.layer.transform = CATransform3DConcat(CATransform3DConcat(CATransform3DMakeRotation(-M_PI_2, 1.0f, .0f, .0f), CATransform3DMakeTranslation(.0f, viewHeight*.5f, .0f)) , baseTransform);
      //or to stay at the same center simply:
      //someView.layer.transform = CATransform3DConcat(CATransform3DMakeRotation(-M_PI_2, 1.0f, .0f, .0f) , baseTransform);
    }];

现在玩一下。

我添加了3D变换示例哇!非常好,谢谢!几乎正是我所需要的,我应该能够找出我自己的最后一部分:)顶部在移动,它应该是静止的。但非常感谢,非常接近;)