自从更新到 iOS8 后,许多动画都停止工作了。看来无法更改 View 的 y
位置。在 iOS7 中没有问题。但在 iOS8 中,它不会超过原来的 y
位置。看起来 View 的框架确实在更新,但框架没有被重绘。这是我的代码
[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];
我也在动画 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);
最佳答案
更新 解决方案是调整自动布局约束而不是 frames
原点。单击您要调整的自动布局约束(在界面构建器中,例如顶部约束)。接下来将其设为 IBOutlet
;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *topConstraint;
然后对其进行动画处理;
self.topConstraint.constant = -100;
[self.viewToAnimate setNeedsUpdateConstraints];
[UIView animateWithDuration:.3 animations:^{
[self.viewToAnimate layoutIfNeeded];
}];
以上代码将移动 View /或向上移动约束。要将其移回到原来的位置,只需调用即可;
self.topConstraint.constant = 0;
[self.viewToAnimate setNeedsUpdateConstraints];
[UIView animateWithDuration:.3 animations:^{
[self.viewToAnimate layoutIfNeeded];
}];
第二种解决方案
我找到了解决方案。看起来如果 self.table
是一个 IBOutlet
那么动画就不会工作。我猜这是新动态 Storyboard的结果。全部在代码中创建元素而不是在 Storyboard 中创建成功的动画。这就是我必须做的让它工作的全部,在代码中创建 UITableView
。
关于UIView transition With View 和设置框架不再适用于 iOS 8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25970457/