[英]How to move view down by animation?
In my app, I implement webview, and under that webview I have a one view and I want to move that view by animation like in Safari. 在我的应用程序中,我实现了webview,在该webview下,我有一个视图,并且想要像Safari中那样通过动画移动该视图。
Here is my code: 这是我的代码:
func scrollViewWillBeginDragging(scrollView: UIScrollView) {
if scrollView.panGestureRecognizer.translationInView(scrollView.superview).y > 0 {
// scrolls down
print("UP")
viewbottom.hidden = false
viewHieght.constant = 45
} else {
print("DOWN")
viewbottom.hidden = true
viewHieght.constant = 0
}
}
In this code I am hiding the view while scroll down but I want to move it down slowly like Safari. 在这段代码中,我在向下滚动时隐藏了视图,但我想像Safari一样将其缓慢向下移动。 So how can I do this?
那我该怎么做呢?
use layoutIfNeeded()
property with animateWithDuration
将
animateWithDuration
layoutIfNeeded()
属性与animateWithDuration
一起animateWithDuration
UIView.animateWithDuration(0.2, animations: { () -> Void in
viewHieght.constant = 45
self.view.layoutIfNeeded()
})
viewHeight.constant = max(0, min(45, scrollView.panGestureRecognizer.translationInView(scrollView.superview).y))
这应该使视图随手势移动,但min为0,max为45
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.