我已经在 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;
}
它以某种方式工作但不正确,一旦我进行旋转, View 就会变大并且左下角和右下角不在 View 中。如果我缩小 View 然后进行 3D 缩放,它也会变得一团糟。我已经通过正确设置图层的 zPosition 解决了一半图像消失的问题,但这是我得到的。 我试过使用其他项目的代码,但它们的所有 3D 立方体效果都与“清除”应用程序不同。唯一接近的是 iCarousel 项目,但我无法使用应用程序中的正确代码,我无法让它工作。有人可以帮助我吗?
最佳答案
以下是一些专门涵盖 UIView 3D 透视变换主题的链接:
http://www.sunsetlakesoftware.com/2008/10/22/3-d-rotation-without-trackball
http://watchingapple.com/2008/04/core-animation-3d-perspective/
关于iphone - UIView 3DCube 像 Clear-app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9416905/