Here's my config:
I have a storyboard with a ListViewController. ListViewController has a subview UIView called EmptyListView. EmptyListView is shown only when there are no items in the UITableView, otherwise it is hidden.
EmptyListView has a subview UIImageView called emptyListViewArrow which visually points towards the button to create a new entry in my UITableView. This arrow is animated infinitely in an up & down fashion.
I listen for EmptyListView to send a notification when it has finished laying out it's subviews. I do this because if not, animations that mutate constraints behave incorrectly.
- (void) layoutSubviews {
[super layoutSubviews];
[[NSNotificationCenter defaultCenter] postNotificationName:@"EmptyViewDidLayoutSubviews" object:nil];
}
When ListViewController observes this notification, it begins the animation:
[UIView animateWithDuration:0.8f delay:0.0f options:(UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse) animations:^{
self.emptyListViewArrowVerticalSpace.constant = 15.0f;
[emptyListView layoutIfNeeded];
} completion:nil];
If I put the app in the background or push another ViewController on the stack, once I come back to the app or the ListViewController, the animation is stopped/paused. I can't get it to start again.
I've tried:
I'm regretting using constraints here, but would love any insight into what could be the problem.
Thank you!
You don't need to use [weak self] in static function UIView. animate() You need to use weak when retain cycle is possible and animations block is not retained by self.
it queries the views objects for changed state and gets back the initial and target values and hence knows what properties to change and in what range to perform the changes. it calculates the intermediate frames, based on the duration and initial/target values, and fires the animation.
The contents of your block are performed on the main thread regardless of where you call [UIView animateWithDuration:animations:] . It's best to let the OS run your animations; the animation thread does not block the main thread -- only the animation block itself.
I was having the same issue. Resolved with the following.
yourCoreAnimation.isRemovedOnCompletion = false
Or you have group of animations
yourGroupAnimation.isRemovedOnCompletion = false
I'm not sure what you're doing with that notification. I've done lots of animations with constraints and never had to do that. I think the problem is that when you leave the view, the constraint's constant value will be 15 (I've verified that with logs in viewWillDisappear), so the animation to set it to 15 will do nothing. In a test app, I set the constant back to its starting value (0) in viewWillAppear, and it worked fine:
-(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];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With