6

我已经搜索了 google 和 stackoverflow 上的所有帖子,但我根本无法解决这个难题。我正在尝试重现现在著名的待办事项应用程序“清除”在添加新任务时的效果。他们有某种动画,从顶部开始,新任务会以某种 3D 立方体效果出现。他们的特别之处在于,当你仔细观察时,左右下角总是保持在同一个地方。

现在我有以下内容:一个 320x460 的 UIView 设置在点 0,0 和一个 320x460 的 UIView 设置在点 (0,-460)。我想要的是顶部 UIView 以与从顶部清除相同的立方体效果下降。这是我到目前为止所拥有的:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    //startLoc is defined globally to remember the first position
    startLoc = [[touches anyObject] locationInView:self];
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    CGPoint location = [[touches anyObject] locationInView:self];
    float difference = location.y-startLoc.y;         

    if(diff > 0 && diff < 90)
    {
        //Init the transform
        CATransform3D transform = CATransform3DIdentity;
        transform.m34 = perspective;
        //Rotate (radians is a degree-to radians function)
        transform = CATransform3DRotate(transform, radians(90-diff), 1.0f, 0.0f, 0.0f);
        //Also translate the view down        
        transform = CATransform3DTranslate(transform, 0.0f, 230+diff, 0.0f);
        //the 230 is necessary I think for the Anchorpoint but I'm not sure
        secondView.layer.transform = transform;
}    

}

它以某种方式工作但不正确,一旦我进行旋转,视图就会变大,左下角和右下角不在视图中。如果我缩小视图然后做一个 3Dscale 它也搞砸了。我已经通过正确设置图层的 zPosition 解决了一半图像消失的问题,但这是我所得到的。我尝试使用其他项目的代码,但它们的所有 3D 立方体效果都与“清除”应用程序不同。唯一接近的是 iCarousel 项目,但我无法使用应用程序中的正确代码,我无法让它工作。有人能帮我吗?

4

2 回答 2

2

以下是一些专门涵盖 UIView 3D 透视变换主题的链接:

http://www.sunsetlakesoftware.com/2008/10/22/3-d-rotation-without-trackball

http://watchingapple.com/2008/04/core-animation-3d-perspective/

这篇文章也很相关:如何将透视变换应用于 UIView?

于 2012-02-23T20:33:53.697 回答
2

您可以查看 GitHub mystcolor/JTGestureBasedTableViewDemo上的开源实现

于 2012-05-04T07:10:47.703 回答