UIView transitionWithView & setting the frame no longer works iOS8

人盡茶涼 提交于 2019-12-10 20:52:36

问题


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);

回答1:


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.



来源:https://stackoverflow.com/questions/25970457/uiview-transitionwithview-setting-the-frame-no-longer-works-ios8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!