2012-07-09 22 views
0

在联系人应用程序中,当您为联系人选择图像时,缩略图图像会用一个很酷的动画加载到位置。它发生在图像选取器解散时。试图复制联系人应用程序的加载缩略图图像动画

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

这是他们怎么做到的?我想实现类似的功能,但是在iPad应用中。如果是这样的话,我必须找出弹出框内的图像帧的坐标。

任何人都知道他们是如何做到这一点的?我在做什么?

回答

0

我不是一个CAAnimation的家伙,但我想它是沿着UIBezierPath一个CAKeyframeAnimation的组合,与边界的一个基本的动画相结合。我的贝塞尔并不完全正确,但你可能会明白这一点。所以,也许它是这样的:

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"]; 
+1

我相信也有一个规模动画,但你看起来不错。 – pasawaya 2012-07-09 22:43:34

+0

@qegal是的,我被这个诱惑了,但是我认为最终静止位置的界限是很关键的(以适应所需的最终用户界面),所以我认为如果RyeMAC3动画界限可能会更容易。但我相信你也可以制作比例动画... – Rob 2012-07-09 22:54:52

+0

很酷,谢谢。我将不得不玩这个。我永远不会想到我自己! – RyeMAC3 2012-07-10 17:45:03