[英]swift animateWithDuration animation not right
I am hiding my navigation bar and a UIView under it that acts as a extension bar to it when I scroll my page. 我隐藏了导航栏和下面的UIView,当我滚动页面时,它充当了它的扩展栏 。
My app is built like: 我的应用程序的构建方式如下:
VC that holds a container view with an embedded table view. VC包含具有嵌入式表视图的容器视图。
From the table view I have delegates that notify VC1 once a user scrolls up or down. 从表视图中,我可以看到一个委托,一旦用户向上或向下滚动,它们就会通知VC1。
My problem now is that the animation dont looks that good. 我现在的问题是动画看起来不那么好。 What I am trying to do is to animate the extension bar to animate up or down with a fade in or fade out effect as well.
我想做的是为扩展栏设置动画,以同时使用淡入或淡出效果对动画进行上下动画处理。 When that occurs I also update the top contraint on my container view so that the table view will fill the whole screen.
发生这种情况时,我还将更新容器视图上的顶部约束,以便表视图将填充整个屏幕。 (I am not sure if I use layoutneeded() right or if something else should be used when updating constraints)
(我不确定是否正确使用layoutneeded()或在更新约束时是否应使用其他方法)
My code: 我的代码:
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 is the extension view tableVConst is the top constraint for my container view that holds my table view extensionV是扩展视图tableVConst是保存我的表视图的容器视图的最高约束
So how should I edit my code in order to get the extension view to animate up/down with a fade in/fade out effect? 那么,如何编辑代码以使扩展视图具有淡入/淡出效果来向上/向下动画?
与其在完成块中调用self.view.layoutIfNeeded()
, self.view.layoutIfNeeded()
在返回之前在最后一行的动画块内调用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.