我有以下代码可以在我的应用程序中为某些 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/