Autolayout 在 iOS 10 中没有动画但在 iOS 9 中工作正常
Autolayout not animating in iOS 10 but working fine in iOS 9
- (IBAction)btnA:(id)sender {
if(self.height.constant == 300) {
self.height.constant = 50;
} else {
self.height.constant = 300;
}
[self.subView1 setNeedsUpdateConstraints];
[UIView animateWithDuration:1.0 animations:^{
[self.subView1 layoutIfNeeded];
}];
}
我正在使用此代码,但在 iOS10
上它没有动画,它只是跳跃增加和减少 mySubview1 高度。为什么?
相同的代码在 iOS9
中运行良好
对于 iOS10 它是您必须强制布局的视图的超级视图。
//Force apply all constraints prior to the change in constant.
[self.view.superview layoutIfNeeded];
//Update constant
self.height.constant = 0;
[UIView animateWithDuration:1.0 animations:^{
[self.view.superview layoutIfNeeded];
}
我认为此行为是由 Xcode8 - iOS10 布局
中的更改引起的
参考文献:
- (IBAction)btnA:(id)sender {
if(self.height.constant == 300) {
self.height.constant = 50;
} else {
self.height.constant = 300;
}
[self.subView1 setNeedsUpdateConstraints];
[UIView animateWithDuration:1.0 animations:^{
[self.subView1 layoutIfNeeded];
}];
}
我正在使用此代码,但在 iOS10
上它没有动画,它只是跳跃增加和减少 mySubview1 高度。为什么?
相同的代码在 iOS9
对于 iOS10 它是您必须强制布局的视图的超级视图。
//Force apply all constraints prior to the change in constant.
[self.view.superview layoutIfNeeded];
//Update constant
self.height.constant = 0;
[UIView animateWithDuration:1.0 animations:^{
[self.view.superview layoutIfNeeded];
}
我认为此行为是由 Xcode8 - iOS10 布局
中的更改引起的参考文献: