UIView 常见翻转动画

2D动画

/**
 *  平移
 *
 *  @param transform 获取当前的形变 transform
 *  @param tx        沿着 x 水平方向的平移
 *  @param ty        沿着 y 垂直方向的平移
 *
 *  @return 返回移动之后的结果
 */
CGAffineTransformTranslate(CGAffineTransform t, CGFloat tx, CGFloat ty)
/**
 *  缩放
 *
 *  @param transform 获取当前的形变 transform
 *  @param sx       水平方向缩放比例
 *  @param sy       垂直方向缩放比例
 *
 *  @return 缩放后结果
 */
CGAffineTransformScale(CGAffineTransform t, CGFloat sx, CGFloat sy)
/**
 *  旋转
 *
 *  @param transform 获取当前的形变 transform
 *  @param angle     旋转角度
 *
 *  @return 返回旋转后的结果
 */
CGAffineTransformRotate(CGAffineTransform t, CGFloat angle)
/**
 *  还原
 */
CGAffineTransformIdentity

Dmoe
//旋转  
self.imageView.transform = CGAffineTransformRotate(self.imageView.transform, M_PI_4);  

//缩放   
self.imageView.transform = CGAffineTransformScale(self.imageView.transform, 0.9, 0.9);  

Y轴3D翻转

3D翻转.gif
- (void) rotateViewAnimated:(UIView*)view
           withDuration:(CFTimeInterval)duration
                byAngle:(CGFloat)angle
{
[CATransaction begin];
CABasicAnimation *rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
rotationAnimation.byValue = [NSNumber numberWithFloat:angle];
rotationAnimation.duration = duration;
rotationAnimation.removedOnCompletion = YES;

[CATransaction setCompletionBlock:^{
    //view.transform = CGAffineTransformRotate(view.transform, angle);
}];

[view.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
[CATransaction commit];
}

水平2D 旋转

2D 旋转.gif
- (void) rotateViewAnimated:(UIView*)view
           withDuration:(CFTimeInterval)duration
                byAngle:(CGFloat)angle
{
[CATransaction begin];
CABasicAnimation *rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.byValue = [NSNumber numberWithFloat:angle];
rotationAnimation.duration = duration;
rotationAnimation.removedOnCompletion = YES;

[CATransaction setCompletionBlock:^{
    //view.transform = CGAffineTransformRotate(view.transform, angle);
}];

[view.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
[CATransaction commit];
}

你可能感兴趣的:(UIView 常见翻转动画)