我是一名Android开发人员,现在开始开发Swift。我想知道如何UIView从底部显示a ,像这样:
到目前为止,我知道如何执行此操作,但是UIViewController有一天将底视图用作,我在Stackoverflow答案中看到了这一点。https://github.com/luangs7/BottomDialogSwift
好吧,总而言之,我只需要从底部显示一个UIView带有自xib定义的即可height。
您可以通过做一些动画工作来实现。如果您使用的是情节提要,请为这样的视图提供约束,
ViewToAnimates.leading = safeArea。Leading“ constant = 0”
ViewToAnimates.trailing = safeArea.trailing“ constant = 0”
ViewToAnimates.top = safeArea.bottom“ constant = 0”(您的视图将置于ViewControllers主视图下方)
现在显示这样的视图
@IBOutlet weak var viewToAnimateOutlet: UIView!
@IBAction func showViewButtonAction(_ sender: Any) {
UIView.animate(withDuration: 1.5) {
self.viewToAnimateOutlet.center.y -= self.viewToAnimateOutlet.frame.height
}
}
@IBAction func hideViewButtonAction(_ sender: Any) {
UIView.animate(withDuration: 1.5) {
self.viewToAnimateOutlet.center.y += self.viewToAnimateOutlet.frame.height
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2518 次 |
| 最近记录: |