更新时间:2023-09-08 19:46:34
当尝试使用自动版式制作动画时,您应该不直接更改视图的帧。
When trying to animate with Auto Layout, you should not change view's frames directly. Instead, you should animate changes in constraints.
要从故事板访问约束,您可以简单地为他们创建IBOutlets 。
[containerView layoutIfNeeded]; // complete pending layout operations (optional)
[UIView animateWithDuration:1.0 animations:^{
// Update constraints
self.viewConstraint1.constant = NEW_VALUE;
self.viewConstraint2.constant = NEW_VALUE;
// Animate the changes
[containerView layoutIfNeeded];
}];
注意,你通常想要调用layoutIfNeeded在超级视图
我建议您阅读Apple的官方指南。
I recommend reading more on Auto Layout in Apple's official guide.