[英]swift animateWithDuration animation not right
我隐藏了导航栏和下面的UIView,当我滚动页面时,它充当了它的扩展栏 。
我的应用程序的构建方式如下:
VC包含具有嵌入式表视图的容器视图。
从表视图中,我可以看到一个委托,一旦用户向上或向下滚动,它们就会通知VC1。
我现在的问题是动画看起来不那么好。 我想做的是为扩展栏设置动画,以同时使用淡入或淡出效果对动画进行上下动画处理。 发生这种情况时,我还将更新容器视图上的顶部约束,以便表视图将填充整个屏幕。 (我不确定是否正确使用layoutneeded()或在更新约束时是否应使用其他方法)
我的代码:
func ContainerTableViewControllerScrolledUp(controller: ContainerTableViewController) {
self.navigationController?.setNavigationBarHidden(false, animated: true)
println("UP")
UIView.animateWithDuration(
1.5,
delay: 0,
usingSpringWithDamping: 0.7,
initialSpringVelocity: 0.5,
options: nil,
animations: {
self.extensionV.alpha = 1
self.tableVConst.constant = 0
}, completion: { finished in
self.view.layoutIfNeeded()
}
)
}
func ContainerTableViewControllerScrolledDown(controller:ContainerTableViewController) {
self.navigationController?.setNavigationBarHidden(true, animated: true)
println("DOWN")
UIView.animateWithDuration(
1.5,
delay: 0,
usingSpringWithDamping: 0.7,
initialSpringVelocity: 0.5,
options: nil,
animations: {
self.extensionV.frame.origin.y = CGFloat(-10)
self.tableVConst.constant = -41
self.extensionV.alpha = 0
}, completion: { finished in
self.view.layoutIfNeeded()
}
)
}
extensionV是扩展视图tableVConst是保存我的表视图的容器视图的最高约束
那么,如何编辑代码以使扩展视图具有淡入/淡出效果来向上/向下动画?
与其在完成块中调用self.view.layoutIfNeeded()
, self.view.layoutIfNeeded()
在返回之前在最后一行的动画块内调用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.