我不是一個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