动画像iPhone的电子邮件应用程序的图像

use*_*789 1 iphone cocoa ios

当想要将电子邮件消息移动到另一个框时,我想为图像设置动画,就像邮件应用程序动画飞出"信封"图标一样.我试图使用CoreAnimation,但我希望它遵循弯曲的路径.

有人可以指出如何做到这一点?

Ani*_*ari 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.   

}
Run Code Online (Sandbox Code Playgroud)

请记住在项目中导入QuartzCore Framework并将其导入头文件中.