UIView transitionWithView and frame setting doesn't work anymore iOS8

Many animations have stopped working since the update to iOS8. It looks like the position of the y

view cannot be changed. There were no problems in iOS7. But with iOS8, it won't get past its previous position y

. It seems that the view frame is 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've 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);

      

+3


source to share


1 answer


Update . The solution is to adjust the auto layout constraints, not the source frames

. Click on the auto-layout constraint you want to customize (in the interface builder, for example, at the top constraint). Then do it IBOutlet

;

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

      

Then animate it;

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

      



The above code moves the view / or moves constraints up. To move it back to its original simple call,

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

      

Second solution I found a solution. It looks like if it self.table

is IBOutlet

, then the animation won't work. I'm guessing this is the result of the new dynamic storyboards. Creating your elements in code, not storyboard, results in a successful animation. That's all I had to do to make it work, create UITableView

in code.

+4


source







All Articles