当想要将电子邮件移动到其他框时,我想为邮件应用设置动画,使其飞出“信封”图标。我尝试使用CoreAnimation,但我希望它遵循弯曲的路径。
有人可以指出如何做到这一点吗?
答案 0 :(得分:7)
UIBeizerPath是可用于在动画期间创建imageObject跟随路径的类。
试试这个动画,我创建它就像iphone中的图像删除动画一样。
- (IBAction)buttonClicked:(id)sender {
UIView *senderView = (UIView*)sender;
if (![senderView isKindOfClass:[UIView class]])
return;
UIView *icon =myImageView;
//move along the path
UIBezierPath *movePath = [UIBezierPath bezierPath];
[movePath moveToPoint:icon.center];
[movePath addQuadCurveToPoint:senderView.center
controlPoint:CGPointMake(senderView.center.x, icon.center.y)];
CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
moveAnim.path = movePath.CGPath;
moveAnim.removedOnCompletion = YES;
//Scale Animation
CABasicAnimation *scaleAnim = [CABasicAnimation animationWithKeyPath:@"transform"];
scaleAnim.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
scaleAnim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1,0.1, 1.0)];
scaleAnim.removedOnCompletion = YES;
CAAnimationGroup *animGroup = [CAAnimationGroup animation];
animGroup.animations = [NSArray arrayWithObjects:moveAnim, scaleAnim, nil];
animGroup.duration = 1.0;
[icon.layer addAnimation:animGroup forKey:nil];
// create timer with time of animation to change the image.
}
请记住在项目中导入QuartzCore Framework并将其导入头文件中。