ios - UIView 动画翻转不工作

标签 ios uiview uiviewanimation

在 UIView 子类中我有这个:

self.frontImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"front"]];
self.backImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"back"]];
[self addSubview:self.backImageView];


[UIView animateWithDuration:0.5
                          delay:0.0
                        options:UIViewAnimationOptionTransitionFlipFromLeft
                     animations:^{
                         [self.backImageView removeFromSuperview];
                         [self addSubview:self.frontImageView];}

                     completion:^(BOOL finished){
                         //nothing
                     }];

但我没有得到翻转动画。正面 ImageView 立即出现。我做错了什么?

最佳答案

你在使用

时犯了一个愚蠢的错误
animateWithDuration:delay:options:animations:completion:

代替

transitionFromView:toView:duration:options:completion:

您的代码应该是:

[UIView transitionFromView:backImageView
                    toView:frontImageView
                  duration:0.5
                   options:UIViewAnimationOptionTransitionFlipFromLeft
                completion:^(BOOL finished) {
                    // animation completed
                }];

关于ios - UIView 动画翻转不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15031793/

相关文章:

ios - 如何找到 UILabel 中文本子字符串的 CGRect?

ios - Cordova iOS 插件安装 pod 安装静默退出

ios - xcode 将文本字符串加载到 UISearchController 中

ios - AVAssetsWriter CVBufferRelease(缓冲区);导致崩溃

iphone - 在行选择处添加 uiview

iphone - 如何在没有 "current" View Controller 的情况下在 iPhone 上呈现模态视图 Controller ?

ios - 将框架设置为 UIView 不起作用

iphone - 调整框架大小后禁用 uiviews 按钮中的用户操作

iphone - UITableView 中的 UIGestureRecognizer - 滚动后崩溃?

ios - 关于iOS Constraint update Animation - Animation block + layoutIfNeeded