2012-03-01 52 views
1

動畫像我想要動畫的圖像就像郵件應用動畫飛出「信封」圖標時,試圖將電子郵件移動到不同的框。我試圖使用CoreAnimation,但我希望它遵循彎曲的路徑。動畫像iPhone的電子郵件應用

有人可以請指出如何做到這一點?

回答

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並將其導入到頭文件中。

相關問題