我不是一个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"];
来源
2012-07-09 22:36:54
Rob
我相信也有一个规模动画,但你看起来不错。 – pasawaya 2012-07-09 22:43:34
@qegal是的,我被这个诱惑了,但是我认为最终静止位置的界限是很关键的(以适应所需的最终用户界面),所以我认为如果RyeMAC3动画界限可能会更容易。但我相信你也可以制作比例动画... – Rob 2012-07-09 22:54:52
很酷,谢谢。我将不得不玩这个。我永远不会想到我自己! – RyeMAC3 2012-07-10 17:45:03