类似于iPhone Camera App的动画,其中捕获的图像落入图片查看器

时间:2013-10-31 08:14:04

标签: ios camera

我正在开发iOS相机应用程序,并希望创建一个类似于默认相机应用程序捕获图像时的动画(不是快门动画)。捕获的图像似乎落入位于屏幕左下角的照片查看器中。关于如何实现这一点的任何想法?我之前没有尝试动画视图控制器,所以我对如何做到这一点感到有些迷失。

*编辑实施问题* 所以我已经学会了如何制作动画,动画似乎可以正常使用测试图像但是当我使用从AVCapture连接返回的实际图像时,动画就会变得混乱。图像看起来扭曲(纵横比有问题),它跟随的路径与实际路径相反。这是我用来制作动画的代码:

- (void)animateImage:(UIImage*) image {

  UIImageView *animator = [[UIImageView alloc]initWithImage:image];
  animator.frame = previewView.frame;
  animator.contentMode = UIViewContentModeScaleAspectFit;
  [self.previewView addSubview:animator];

  [CATransaction begin]; {
      [CATransaction setCompletionBlock:^{
              [animator removeFromSuperview];
      }];

    // Set up scaling
      CABasicAnimation *resizeAnimation = [CABasicAnimation animationWithKeyPath:@"bounds"];
    // Set to value to (0,0) rectangle
    [resizeAnimation setToValue:[NSValue valueWithCGSize:CGSizeMake(0,0)]];
    resizeAnimation.fillMode = kCAFillModeForwards;
    resizeAnimation.removedOnCompletion = NO;

    // Set up path movement
    CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    pathAnimation.calculationMode = kCAAnimationPaced;
    pathAnimation.fillMode = kCAFillModeForwards;
    pathAnimation.removedOnCompletion = NO;
    //Setting Endpoint of the animation
    CGPoint endPoint = CGPointMake( animator.frame.size.width, animator.frame.size.height); 
    CGMutablePathRef curvedPath = CGPathCreateMutable();
    CGPathMoveToPoint(curvedPath, NULL, 0, 0);
  //  CGPathMoveToPoint(curvedPath, NULL, animator.frame.size.width/2, animator.frame.size.height/2);
  //  CGPathAddCurveToPoint(curvedPath, NULL, 0,0,0,0, endPoint.x, endPoint.y);
    CGPathAddLineToPoint(curvedPath, NULL, endPoint.x, endPoint.y);
    pathAnimation.path = curvedPath;
    CGPathRelease(curvedPath);

    CAAnimationGroup *group = [CAAnimationGroup animation];
 //   group.fillMode = kCAFillModeForwards; // keep the final value after completion of animation
 //   group.removedOnCompletion = NO; // "
    [group setAnimations:[NSArray arrayWithObjects: pathAnimation,  resizeAnimation, nil]];
    group.duration = 3.0f;
    group.delegate = self;
    [group setValue:animator forKey:@"imageViewBeingAnimated"];

    [animator.layer addAnimation:group forKey:@"cameraAnimation"];
} [CATransaction commit];
}

当我以横向模式拍摄照片时,它似乎有效,但在“人像”中却没有。这与方向有关,但我无法弄清楚可能出现的问题......

“previewView”框架是AVCapture预览图层,我在其上添加UIImage,然后缩放并将其移动到角落。

*最终编辑* 修复了使用transform属性而不是bounds.size。与此处的示例类似: http://www.verious.com/article/animating-interfaces-with-core-animation-part-3/ 呼!

1 个答案:

答案 0 :(得分:2)

真的很简单,在拍摄照片后,将返回的UIimage粘贴在UIImageView中,然后使用核心动画块来调整帧的动画,同时使图像视图沿着bezier路径向下移动到左边的照片查看器角。

如果您需要任何有关这些步骤的进一步帮助,请与我们联系。