Iphone UIView动画在视图消失时停止,不';当它再次出现时,将无法恢复
这是我的配置: 我有一个带有ListViewController的故事板。ListViewController有一个名为EmptyListView的子视图UIView。只有当UITableView中没有项目时,才会显示EmptyListView,否则它将隐藏 EmptyListView有一个名为emptyListViewArrow的子视图UIImageView,它直观地指向按钮以在my UITableView中创建新条目。此箭头以向上和向下的方式无限设置动画 我监听EmptyListView在完成其子视图布局后发送通知。我这样做是因为如果不这样做,则会导致变异约束的动画行为不正确Iphone UIView动画在视图消失时停止,不';当它再次出现时,将无法恢复,iphone,ios,ios6,uiview,uiviewanimation,Iphone,Ios,Ios6,Uiview,Uiviewanimation,这是我的配置: 我有一个带有ListViewController的故事板。ListViewController有一个名为EmptyListView的子视图UIView。只有当UITableView中没有项目时,才会显示EmptyListView,否则它将隐藏 EmptyListView有一个名为emptyListViewArrow的子视图UIImageView,它直观地指向按钮以在my 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,动画将停止/暂停。我无法让它重新开始
我试过:
谢谢大家! 我不知道你在用那个通知做什么。我做过很多有约束的动画,从来没有做过。我认为问题在于,当您离开视图时,约束的常量值将为15(我已经验证了,在ViewLogs中,约束将消失),因此将其设置为15的动画将不起任何作用。在一个测试应用程序中,我在ViewWillDisplay中将常量设置回其起始值(0),并且效果良好:
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.bottomCon.constant = 0;
[self.view layoutIfNeeded];
}
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[UIView animateWithDuration:1 delay:0.0f options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse animations:^{
self.bottomCon.constant = -40.0f;
[self.view layoutIfNeeded];
} completion:nil];
}
这就是缺点。 要克服此问题,必须再次调用动画方法 您可以按如下方式进行操作: 在控制器中添加观察者
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resumeAnimation:) name:UIApplicationDidBecomeActiveNotification object:nil];
一旦您恢复应用程序,将调用此命令
添加此方法:
- (void)resumeAnimation:(NSNotification *)iRecognizer {
// Restart Animation
}
NotificationCenter.default.addObserver(self, selector: #selector(enterInForeground), name: NSNotification.Name(rawValue: NSNotification.Name.UIApplicationWillEnterForeground.rawValue), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(enterInBackground), name: NSNotification.Name(rawValue: NSNotification.Name.UIApplicationDidEnterBackground.rawValue), object: nil)
func enterInForeground() {
self.animateTheLaserLine()
}
func enterInBackground() {
// reset the position when app enters in background
// I have added the animation on layout constrain you can take your
// component
self.laserTopConstrain.constant = 8
}
希望这会对您有所帮助。当应用程序进入后台,然后再次回到前台时,您将面临同样的问题: Swift:
- (void)resumeAnimation:(NSNotification *)iRecognizer {
// Restart Animation
}
NotificationCenter.default.addObserver(self, selector: #selector(enterInForeground), name: NSNotification.Name(rawValue: NSNotification.Name.UIApplicationWillEnterForeground.rawValue), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(enterInBackground), name: NSNotification.Name(rawValue: NSNotification.Name.UIApplicationDidEnterBackground.rawValue), object: nil)
func enterInForeground() {
self.animateTheLaserLine()
}
func enterInBackground() {
// reset the position when app enters in background
// I have added the animation on layout constrain you can take your
// component
self.laserTopConstrain.constant = 8
}
我也有同样的问题。解决方法如下
yourCoreAnimation.isRemovedOnCompletion = false
或者你有一组动画
yourGroupAnimation.isRemovedOnCompletion = false
我遇到了同样的问题。我将动画应用于viewDidLoad中的imageView
UIView.animate(withDuration: 0.5, delay: 0, options: [.repeat, .autoreverse, ], animations: {
self.myImageView.transform = self.transform
self.myImageView.alpha = 0.7
}
但每当我推其他VC回来时,动画就不起作用了
什么对我有用
视图中的动画将消失
myImageView.transform=.identity
myImageView.alpha=1
UIView.animate()
)也将出现希望这有帮助您是否在
viewdiload
或viewwillbeen
中使用您的方法?viewdilbeen,但不是出于任何特定原因。您知道这是否会阻止视图控制器解除分配?