5
这里是我的代码移动UIview 30px然后到y = 10但这个动画不起作用。这是我第一次尝试创建CAKeyframeAnimation,因此任何人都可以帮助我正确写入它。另外我希望我的对象不会回到原来的位置,而是呆在那里动画结束的地方。CAKeyframeanimation沿着路径移动UIView
CGMutablePathRef thePath = CGPathCreateMutable();
CGPathAddRect(thePath, NULL, CGRectMake(self.logo.frame.origin.x, self.logo.frame.origin.y, self.logo.frame.size.width, self.logo.frame.size.height));
CGPathAddRect(thePath, NULL, CGRectMake(self.logo.frame.origin.x, self.logo.frame.origin.y-30, self.logo.frame.size.width, self.logo.frame.size.height));
CGPathAddRect(thePath, NULL, CGRectMake(self.logo.frame.origin.x, 100, self.logo.frame.size.width, self.logo.frame.size.height));
CAKeyframeAnimation* AniLoc = [CAKeyframeAnimation animationWithKeyPath:@"frame"];
AniLoc.path = thePath;
AniLoc.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
AniLoc.keyTimes= [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0f],
[NSNumber numberWithFloat:0.3f],
[NSNumber numberWithFloat:1.0f],nil];
AniLoc.duration = 2.0;
CFRelease(thePath);
[self.logo.layer addAnimation:AniLoc forKey:nil];
它以什么方式“不工作”? – jrturton 2012-01-09 14:06:41
动画没有移动任何东西 – 2012-01-09 14:13:57