【问题标题】:Animation similar to iPhone Camera App where the captured image drops into the picture viewer类似于 iPhone Camera App 的动画,其中捕获的图像落入图片查看器
【发布时间】:2013-10-31 08:14:04
【问题描述】:

我正在开发一个 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,然后缩放并将其移动到角落。

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

【问题讨论】:

    标签: ios camera


    【解决方案1】:

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

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

    【讨论】:

    • 太棒了,谢谢,你这么说听起来很简单:)
    • 没问题,如果您在这些步骤中需要任何帮助,请告诉我,我会提供示例代码...
    • 我已经设法让一些动画工作,但我的图像方向似乎有一个奇怪的问题,你能看看吗?
    猜你喜欢
    • 1970-01-01
    • 2011-03-12
    • 2017-09-25
    • 1970-01-01
    • 1970-01-01
    • 2018-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多