ios - 类似于 iPhone 相机应用程序的动画,其中捕获的图像落入图片查看器

标签 ios camera

我正在开发一个 iOS 相机应用程序,我想创建一个类似于默认相机应用程序在捕获图像时所做的动画(不是快门动画)。捕获的图像似乎落入位于屏幕左下角的照片查看器中。关于如何实现这一目标的任何想法?我以前没有尝试过为 View Controller 设置动画,所以我有点不知道该怎么做。

* 编辑实现问题 * 所以我已经学会了如何制作动画,并且动画似乎可以很好地与测试图像一起使用,但是当我使用从 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/ 呸!

最佳答案

这真的很简单,拍照后,将返回的 UIimage 粘贴到 UIImageView 中,然后使用核心动画 block 调整框架的大小和动画,同时使 imageview 沿着 bezierpath 向下移动到左下角的照片查看器角落。

如果您需要有关这些步骤的任何进一步帮助,请告诉我。

关于ios - 类似于 iPhone 相机应用程序的动画,其中捕获的图像落入图片查看器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19701293/

相关文章:

ios - iOS8中的自定义GIF键盘

ios - 是否需要针对 iPhone 5 的屏幕修改应用程序?

ios - 为什么在交互和滚动时 UITableView 会发生内存泄漏?

android - onResume 后相机表面 View 不可见

android - 摄像机变焦

java - LibGDX - 平移相机时屏幕上没有任何变化

ios - 在方向更改时重新加载 UIPageViewController View

android - Qt QML Camera 到 Android 上的 C++ QImage

vb.net - Sony Camera Remote API,如何使用 VB.net 显示/使用 liveview-stream 数据(使用 Sony QX1)

ios - 相机不聚焦在运行 iOS 7.1 的 iPhone 4 上