iOS 7 动画 block 未被调用

标签 ios objective-c-blocks uiviewanimation ios7

我有以下代码可以在我的应用程序中为某些 View 设置动画:

void (^animate)() = ^() {
    CGRect leftFrame = centerFrame;
    leftFrame.origin.x -= centerFrame.size.width;
    newViewController.view.frame = centerFrame;
    oldViewController.view.frame = leftFrame;
};

if (animated) {
    [UIView animateWithDuration:0.3f
                          delay:0.0f
                        options:nil
                     animations:animate
                     completion:^(BOOL finished){}];
} else {
    animate();
}

此动画在 iOS 6 上正确,但在 iOS 7 上没有动画。奇怪的是, block 内的代码确实被调用并且 View 确实更新,只是没有考虑动画持续时间。

这个 block 没有被调用是有原因的吗?

最佳答案

我遇到了同样的问题:一个在 iOS6 中像魅力一样工作的动画 block 在 iOS7 中执行时没有动画。

不确定这是否对您有帮助,但我将动画触发器移至 viewDidAppear:,现在它已被激活。

所以对你来说这可能看起来像这样:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    animate();
    // do your other stuff here...
}

关于iOS 7 动画 block 未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18880584/

相关文章:

ios - 照片框架 : UICollectionView scrolling jitter

ios - 在哪里放置 MVC 的编程约束

iphone - 使用 GCD 创建循环

iOS/objective-C : How can I mix delegation and blocks?

swift - 动画后无法隐藏 View

iphone - 对第 3 方日历应用程序的 iPhone 通知区域进行更多控制

ios - 如何使用 New>File... 模板 "wizard"在 Xcode 6 中创建 UITableViewController

iOS( objective-C )。从数组中获取 block 时应用程序崩溃

swift - UIViewPropertyAnimator 无法通过 View 之间的平移手势正确停止

ios - 如何在两个 UIView 之间实现 "90% slide"