2

I cannot figure out how to set NSLayoutConstraint animation duration in iOS7. Here's my code:

self.loadingViewTop.constant = -[[UIScreen mainScreen] bounds].size.height;
self.loadingViewBottom.constant = [[UIScreen mainScreen] bounds].size.height;

[UIView animateWithDuration:30.0f animations:^{
    [self.loadingView setNeedsUpdateConstraints];
}];
Dmitry
  • 245
  • 1
  • 2
  • 9
  • possible duplicate of [Are NSLayoutConstraints animatable?](http://stackoverflow.com/questions/12926566/are-nslayoutconstraints-animatable) – Wain Jan 31 '14 at 13:19
  • @iiFreeman I tried it. Actually if you remove [UIView animateWithDuration] code the view still animates. I cannot see any possible solution how to control it. – Dmitry Jan 31 '14 at 13:23

2 Answers2

2

Oh you forget to call [self.view layoutIfNeeded]; inside animation block

iiFreeman
  • 5,165
  • 2
  • 29
  • 42
  • I tried it as well. It does not make any difference. I think layout constraints behave differently in iOS7. Code which worked well in iOS6 does not work any more. – Dmitry Jan 31 '14 at 13:26
  • did you check your constants are actually not nil? – iiFreeman Jan 31 '14 at 13:28
  • Ok I got it working. Here's the right way of doing it: self.loadingViewTop.constant = -[[UIScreen mainScreen] bounds].size.height; self.loadingViewBottom.constant = [[UIScreen mainScreen] bounds].size.height; [UIView animateWithDuration:30.0f animations:^{ [self.view layoutIfNeeded]; }]; – Dmitry Jan 31 '14 at 13:30
1

The solution:

self.loadingViewTop.constant = -[[UIScreen mainScreen] bounds].size.height;
self.loadingViewBottom.constant = [[UIScreen mainScreen] bounds].size.height;

[UIView animateWithDuration:30.0f animations:^{
    [self.view layoutIfNeeded];
}];
Dmitry
  • 245
  • 1
  • 2
  • 9