ios - 隐藏带有约束和动画的视图
问题描述
我有UIViewController
一个习惯TabBarController
。在里面我有一个UIView
whichUIViewController
和在底部另一个UIView
作为 a 的功能TabBar
,我想隐藏TabBar
with 动画并保持约束有序。出于某种原因,每次我尝试这样做时,视图约束都会变得一团糟。
具有 100 点的TabBar
恒定高度。
- UIViewController
- viewContent (UIView, the UIViewController container)
- viewTabBar (UIView as TabBar)
这是我的代码:
func hideTabBar() {
UIView.animate(withDuration: 400) {
self.contentView.frame.size.height += self.viewTabBar.frame.size.height
self.view.layoutIfNeeded()
}
}
帮助?
解决方案
我猜想做到这一点的最佳方法是将标签栏高度约束设为 IBOutlet,或者只是以编程方式创建它,然后只需更改该约束常量值。像这样的东西:
var tabbarHeightConstraint = NSLayoutConstraint(item: tabbarView, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .none, multiplier: 1, constant: 100)
NSLayoutConstraint.activate([tabbarHeightConstraint])
// Animating, set new tab bar height to 0
tabbarHeightConstraint.constant = 0
UIView.animate(withDuration: 400) {
self.view.layoutIfNeeded() // Or wherever the tabbar view is in
}
现在,如果您想再次显示标签栏,只需执行相同操作,但将常量设置为 100。
推荐阅读
- firebase - 为 Google Analytics(分析)网络 + 应用程序属性安排电子邮件报告
- django - 位置参数缺少“状态”
- java - 如何让 Spring Tools Suite 识别 spring 注释
- mongodb - Mongo DB中基于光标的分页,其中跳过或限制未知
- laravel - 如何在 plesk 服务器上处理 SQLSTATE[HY000] [1045] 错误?
- javascript - 使用 HTML、CSS 和 JS 的侧边栏中的多级下拉菜单
- elixir - 模块执行时如何将当前上下文带入模块中?
- linux - 如何检查文件是否来自 tmpfs 内存缓存或磁盘缓存
- r - ak fold cross validation 与开发集中的 AUC/Sensitivity/Specificity 值有何不同?
- google-cloud-platform - Deploying a Cloud Function from Cloud Build with --allow-unauthenticated