0

在“联系人”应用程序中,当您为联系人选择图像时,缩略图图像会以很酷的动画加载到位。它发生在图像选择器关闭时。

如果我不得不猜测,就在图像选择器被关闭时,图像被放入与图像选择器裁剪区域的大小和位置相匹配的 UIIMageView 中。然后 UIImageView 被缩小并就位。但它看起来像沿着曲线动画。

他们是这样做的吗?我想实现类似的东西,但在 iPad 应用程序中。如果是这种情况,我必须找出弹出框内图像框架的坐标。

有人知道他们是怎么做到的吗?我在做某事吗?

4

1 回答 1

0

我不是一个CAAnimation人,但我想它是 a 和 a 的组合CAKeyframeAnimationUIBezierPath结合了边界的基本动画。我的贝塞尔曲线不太正确,但您可能明白了。所以,也许它是这样的:

CGPoint center      = CGPointMake(self.view.frame.size.width / 2.0, self.view.frame.size.height / 2.0);
CGRect  finalRect   = CGRectMake(0.0, 0.0, 75.0, 75.0);
CGPoint finalCenter = CGPointMake(25.0, 25.0);

UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:center];
[path addCurveToPoint:finalCenter
        controlPoint1:CGPointMake(self.view.frame.size.width, 0.0) 
        controlPoint2:CGPointMake(100.0, finalCenter.y)];

UIImage *image = [UIImage imageNamed:@"YOURIMAGE.png"];
NSAssert(image, @"Error loading image");
CALayer *imageLayer = [CALayer layer];
imageLayer.contents = (id)image.CGImage;
imageLayer.bounds   = finalRect;
imageLayer.position = finalCenter;
[self.view.layer addSublayer:imageLayer];

CAKeyframeAnimation *animatePosition = [CAKeyframeAnimation animationWithKeyPath:@"position"];
animatePosition.path = [path CGPath];
animatePosition.duration = 2.0;
[imageLayer addAnimation:animatePosition forKey:@"arc"];

CABasicAnimation *animateBounds = [CABasicAnimation animationWithKeyPath:@"bounds"];
animateBounds.duration = 2.0;
animateBounds.fromValue = [NSValue valueWithCGRect:self.view.bounds];
animateBounds.toValue = [NSValue valueWithCGRect:finalRect];
[imageLayer addAnimation:animateBounds forKey:@"zoom"];
于 2012-07-09T22:36:54.150 回答