3

Since updating to iOS8 many animations have stopped working. It appears that the y position of the view cannot be changed. In iOS7 there was no problem. But with iOS8 it will not go past the original y position.It appears that the frame of the view are indeed being updated but the frame is not being redrawn. Here is my code

[UIView transitionWithView:self.view duration:0.3 options:UIViewAnimationOptionCurveEaseInOut animations:^{

self.table.frame = CGRectMake(0, (self.view.bounds.size.height - self.button.frame.size.height) - (252), self.view.bounds.size.width, self.table.frame.size.height);


} completion:nil];

I have also tried this code outside of the animation block;

  self.table.frame = CGRectMake(0, (self.view.bounds.size.height - self.button.frame.size.height) - (252), self.view.bounds.size.width, self.table.frame.size.height);
DevC
  • 6,982
  • 9
  • 45
  • 80

1 Answers1

4

Update The solution is to adjust the auto layout constraints and not the frames origin. Click on the auto layout constraint you would like to adjust (in interface builder e.g top constraint). Next make this an IBOutlet;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *topConstraint;

Then to animate it;

 self.topConstraint.constant = -100;
[self.viewToAnimate setNeedsUpdateConstraints];  
    [UIView animateWithDuration:.3 animations:^{
        [self.viewToAnimate layoutIfNeeded]; 
    }];

The above code will move the view/ or move the constraints upwards. To move it backdown to its original simply call;

  self.topConstraint.constant = 0;
[self.viewToAnimate setNeedsUpdateConstraints];
    [UIView animateWithDuration:.3 animations:^{
        [self.viewToAnimate layoutIfNeeded]; 
    }];

Second Solution I found the solution. It appears that if self.table is an IBOutlet then the animation wont work. I am guessing this a result of the new dynamic storyboards. Creating your elements all in code and not in the storyboard leads to a successful animation. That is all I had to do to get it to work, create the UITableView in code.

DevC
  • 6,982
  • 9
  • 45
  • 80
  • If anyone is also stuck with this, then don't use [self.viewToAnimate layoutSubviews]; inside animations block as it is not working. Use [self.viewToAnimate layoutIfNeeded]; instead. – Borzh Apr 20 '15 at 17:24
  • @Borzh thats what the original answer says? – DevC Apr 20 '15 at 18:46
  • Yes, I just wanted to emphasize that layoutIfNeeded method is needed and not layoutSubviews. The problem is that layoutSubviews is working on iOS 7.1 but not on iOS 8+ – Borzh Apr 20 '15 at 18:48