Autolayout - 屏幕底部的 UIView 动画
Autolayout - UIView animation from the bottom of the screen
我在我的应用程序中使用了自动布局。我在屏幕底部有一个 UIPicker。我想做的是点击 UIButton 从屏幕底部打开 UIPicker,如下图所示
我想知道
- 我最初必须设置哪种约束
- 我必须以编程方式实施哪种约束以及如何实施?
如何回到原来的位置?
最初将 pickerView
的顶部固定到 SuperView
的 bottom
,然后当您想要它显示时,您可以将 pickerView
的 bottom
固定到底部共 superView
.
或
您可以通过将 pickerView 的底部固定到 superView 的底部并将高度设置为 0 来实现更高的动画效果,并且当您想要显示设置的高度常量以达到所需的高度时。
按照以下步骤操作。
已将此约束应用于您的对象。
之后 select 垂直 space 约束并为其创建 IBOutlet。
@属性(弱,非原子)IBOutlet NSLayoutConstraint *TopHeight;
使用下方设置您想要的上边距 code.it 将为您的对象设置新的带动画的上边距。
self.TopHeight.constant = 400;
[self.view setNeedsUpdateConstraints];
[UIView animateWithDuration:0.5 animations:^{
[self.view layoutIfNeeded];
}];
我所做的是,我为 pickerView 设置了 3 个约束,如下所示。
然后我把底部的出口space设置为我的视图。
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *bottomConstraint;
点击按钮后,我编写了以下逻辑,我的工作就完成了。
- (IBAction)showPicker:(id) sender{
self.bottomConstraint.constant = 0;
[self.picker setNeedsUpdateConstraints];
[UIView animateWithDuration:0.3f animations:^{
[self.view layoutIfNeeded];
}];
}
我在我的应用程序中使用了自动布局。我在屏幕底部有一个 UIPicker。我想做的是点击 UIButton 从屏幕底部打开 UIPicker,如下图所示
我想知道
- 我最初必须设置哪种约束
- 我必须以编程方式实施哪种约束以及如何实施?
如何回到原来的位置?
最初将 pickerView
的顶部固定到 SuperView
的 bottom
,然后当您想要它显示时,您可以将 pickerView
的 bottom
固定到底部共 superView
.
或
您可以通过将 pickerView 的底部固定到 superView 的底部并将高度设置为 0 来实现更高的动画效果,并且当您想要显示设置的高度常量以达到所需的高度时。
按照以下步骤操作。
已将此约束应用于您的对象。
之后 select 垂直 space 约束并为其创建 IBOutlet。
@属性(弱,非原子)IBOutlet NSLayoutConstraint *TopHeight;
使用下方设置您想要的上边距 code.it 将为您的对象设置新的带动画的上边距。
self.TopHeight.constant = 400;
[self.view setNeedsUpdateConstraints];
[UIView animateWithDuration:0.5 animations:^{
[self.view layoutIfNeeded];
}];
我所做的是,我为 pickerView 设置了 3 个约束,如下所示。
然后我把底部的出口space设置为我的视图。
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *bottomConstraint;
点击按钮后,我编写了以下逻辑,我的工作就完成了。
- (IBAction)showPicker:(id) sender{
self.bottomConstraint.constant = 0;
[self.picker setNeedsUpdateConstraints];
[UIView animateWithDuration:0.3f animations:^{
[self.view layoutIfNeeded];
}];
}