我正在快速设计一个 iOS 应用程序,我在 Controller 转换期间遇到动画方面的一些困难。具体来说,我实现了一个 UINavigationControllerDelegate,用于监听某个 View 何时被推送。推送此 View 时,我想在屏幕底部隐藏一个栏。我的代码几乎完美地工作,但是每当我在导航 Controller 的高度上开始动画时,当前 View (正在删除)正确地设置其高度的动画,但是被推送的新 Controller 已经具有新的高度动画。为了向其中添加一些代码,从我的 UINavigationControllerDelegate 的 willShow viewController 函数中调用了以下函数:
func animatePlayerVisibility(_ visible: Bool) {
if visible == showingPlayer {
return
}
showingPlayer = visible
let height: CGFloat = visible ? 56.0 : 0.0
self.view.layoutIfNeeded()
UIView.animate(withDuration: 0.35) {
self.playerHeight.constant = height
self.viewBottom.constant = height
self.view.layoutIfNeeded()
}
}
'playerHeight' 是一个 IBOutlet,用于限制播放器容器 View 的高度。 'viewBottom' 也是顶部容器 View 底部和屏幕底部之间的 IBOutlet 约束。本质上,只要这两个约束一起动画,它应该看起来不错。
为了帮助可视化图形错误,我编辑了这一行
self.viewBottom.constant = height
到
self.viewBottom.constant = height * 2.0
我创建了一个实际错误行为的 imgur 相册: http://imgur.com/a/znAim
如您所见,当新 Controller 已经具有新的动画尺寸时,旧的 View Controller 可以正确地进行动画处理。
任何帮助将不胜感激。我已经尝试解决这个问题一段时间了,但没有成功。
编辑:未应用 *2 的动画 View 。 https://imgur.com/a/2a5Sw
最佳答案
有没有想过不用UINavigationController?也许使用 ChildViewControllers
机制会更容易。然后有了它,您可以使用强大的自动布局并更好地控制动画(在您的情况下高度)
有关此的更多信息 here
关于ios - 在 Controller 转换期间动画化 UINavigationController 高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43968108/