//對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];
另參考:
// 也可以通過對UIView.layer做矩陣做相應的變換達到動畫的效果
//例如
[UIView beginAnimations:nil context:NULL];
CGAffineTransform moveTransform = CGAffineTransformMakeTranslation(180, 200);
[imageView.layer setAffineTransform:moveTransform];
imageView.layer.opacity = 1;
[UIView commitAnimations];
另參考: