iphone - UIView 3DCube 像 Clear-app

标签 iphone ios core-animation catransformlayer

我已经在 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 项目,但我无法使用应用程序中的正确代码,我无法让它工作。有人可以帮助我吗?

最佳答案

关于iphone - UIView 3DCube 像 Clear-app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9416905/

相关文章:

objective-c - 如何检测捏合手势与捏合手势?

ios - 旋转 3D 立方体,使一面朝向用户

objective-c - 如何在 UIButton 的子层上绘制?

iphone - 如何将大 (60mb+) 图像保存到照片库?

iphone - 将图像保存在某处并在另一个 ViewController (iOS) 中使用它

iphone - 为什么我不能在 Obj-C 中声明像 "newVariable"这样的变量?

iphone - 将多个转换应用于 UIView/CALayer

iOS9 - 无法验证任何应用程序

ios - 如果条件失败则 swift

ios - CoreData 关系 , 与 Delete