IOS中通過Core Animation實現簡單動畫

//對UIImageView的旋轉
//CATransaction
//    imageView.layer
    [CATransaction begin];
    [CATransaction setValue:[NSNumber numberWithFloat:1.0] forKey:kCATransactionAnimationDuration];
    //按Y軸旋轉
    CABasicAnimation *FlipAnimation=[CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
    FlipAnimation.timingFunction= [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    //旋轉按弧度M_PI,就是180度
    FlipAnimation.toValue= [NSNumber numberWithFloat:M_PI];
    FlipAnimation.duration=1;
    //旋轉後保持狀態
    FlipAnimation.fillMode=kCAFillModeForwards;
    FlipAnimation.removedOnCompletion=NO;
    [imageView.layer addAnimation:FlipAnimation forKey:@"flip"];
    [CATransaction commit];

另參考:

1、IOS中通過Core Animation實現簡單動畫

2、IOS----Core Animation介紹1



//    也可以通過對UIView.layer做矩陣做相應的變換達到動畫的效果

//例如
 [UIView beginAnimations:nil context:NULL];
    CGAffineTransform moveTransform = CGAffineTransformMakeTranslation(180, 200);
    [imageView.layer setAffineTransform:moveTransform];
    imageView.layer.opacity = 1;
    [UIView commitAnimations];

另參考:

1、CGAffineTransform相關函數

2、轉換矩陣

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章