【发布时间】:2013-09-05 03:41:01
【问题描述】:
这是我的配置:
我有一个带有 ListViewController 的故事板。 ListViewController 有一个名为 EmptyListView 的子视图 UIView。 EmptyListView只有在UITableView中没有item时才会显示,否则隐藏。
EmptyListView 有一个名为 emptyListViewArrow 的 UIImageView 子视图,它在视觉上指向按钮以在我的 UITableView 中创建一个新条目。此箭头以向上和向下的方式无限动画化。
我监听 EmptyListView 在完成子视图布局后发送通知。我这样做是因为如果不是这样,改变约束的动画就会出现不正确的行为。
- (void) layoutSubviews {
[super layoutSubviews];
[[NSNotificationCenter defaultCenter] postNotificationName:@"EmptyViewDidLayoutSubviews" object:nil];
}
当 ListViewController 观察到这个通知时,它开始动画:
[UIView animateWithDuration:0.8f delay:0.0f options:(UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse) animations:^{
self.emptyListViewArrowVerticalSpace.constant = 15.0f;
[emptyListView layoutIfNeeded];
} completion:nil];
如果我将应用程序置于后台或将另一个 ViewController 推入堆栈,一旦我回到应用程序或 ListViewController,动画就会停止/暂停。我无法让它重新开始。
我试过了:
- 监听应用程序将退出/变为活动状态。辞职时,我做了[self.view.layer removeAllAnimations],然后尝试使用上面的代码再次启动动画。
- 删除正在动画的 UIImageView 并将其添加回父视图,然后尝试启动动画。
我很遗憾在这里使用约束,但希望能深入了解可能存在的问题。
谢谢!
【问题讨论】:
-
你在使用
viewDidLoad或viewWillAppear中的方法吗? -
viewDidAppear,但不是出于任何特殊原因。
标签: iphone ios ios6 uiview uiviewanimation