UIImageview旋转动画

UIImageview rotation animation

我想对两个应用动画 UIImageViews。想法是让图像一水平翻转 90 度,然后图像二完成旋转。把它想象成硬币旋转:头侧(图一)面向前方 -> 旋转 90 度 -> 尾侧(图二)旋转面向前方。我可以做动画的前半部分,但我卡在了后半部分。

[UIView animateWithDuration:1.0f animations:^{
    image1.transform = CGAffineTransformMakeScale(-0.01, 1);
} completion: ^(BOOL finished) {
    // How can I make image 2 to rotate out as if it initially was already rotated by 90 degrees?
}];

对于翻转动画,有一个动画选项叫做UIViewAnimationOptionTransitionFlipFromRight,例如使用UIView's动画方法,如下例

 [UIView transitionWithView:myImageView //with first image
                  duration:animationDuration
                   options:UIViewAnimationOptionTransitionFlipFromRight
                animations:^{
                    myImageView.image = toImage; //to next image
                } completion:^(BOOL finished) {
             //completion actions after flipped
 }];

还有其他动画选项,例如 FromLeftFromTop,FromBottom 根据您的要求使用任何一个

看看这个关于使用 CATransform3D 在 3D 中翻转 UIView 的问题。

Simple Core Animations 3D transform of UIView

答案:

CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
rotationAndPerspectiveTransform.m34 = 1.0 / -1000.0;
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, M_PI * 0.6, 1.0f, 0.0f, 0.0f);
[UIView animateWithDuration:1.0 animations:^{
    self.someView.layer.anchorPoint = CGPointMake(0.5, 0);
    self.someView.layer.transform = rotationAndPerspectiveTransform;
} completion:^(BOOL finished){
    // code to be executed when flip is completed
}];