我搜索了谷歌和stackoverflow上的所有帖子,但我根本无法解决这个难题。 我正在尝试重新创建现在着名的todo应用'Clear'在添加新任务时所做的效果。他们有某种动画,从顶部新任务出现在某种3D立方体效果中。他们的特殊之处在于,当你仔细观察时,左下角和下角总是停留在同一个地方。
现在我有以下内容:在点0,0设置了一个320x460的UIView,在点(0,-460)设置了一个320x460的UIView。我想要的是顶部的UIView与顶部的Clear相同的立方体效果。这就是我到目前为止所做的:
-(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项目,但我无法使用应用程序中的正确代码,我无法让它工作。有人能帮助我吗?
答案 0 :(得分:2)
以下是一些专门介绍UIView 3D透视转换主题的链接:
http://www.sunsetlakesoftware.com/2008/10/22/3-d-rotation-without-trackball
http://watchingapple.com/2008/04/core-animation-3d-perspective/
这篇文章也很相关:How do I apply a perspective transform to a UIView?
答案 1 :(得分:2)
您可以在GitHub上查看开源实现{{3p>