如何通过动画向下移动视图?
How to move view down by animation?
在我的应用程序中,我实现了 webview,在该 webview 下我有一个视图,我想像在 Safari 中一样通过动画移动该视图。
这是我的代码:
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
}
}
在这段代码中,我在向下滚动时隐藏了视图,但我想像 Safari 一样慢慢向下移动它。那我该怎么做呢?
viewHeight.constant = max(0, min(45, scrollView.panGestureRecognizer.translationInView(scrollView.superview).y))
这应该使视图随手势移动,但最小值为 0,最大值为 45
使用 layoutIfNeeded()
属性 和 animateWithDuration
UIView.animateWithDuration(0.2, animations: { () -> Void in
viewHieght.constant = 45
self.view.layoutIfNeeded()
})
在我的应用程序中,我实现了 webview,在该 webview 下我有一个视图,我想像在 Safari 中一样通过动画移动该视图。
这是我的代码:
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
}
}
在这段代码中,我在向下滚动时隐藏了视图,但我想像 Safari 一样慢慢向下移动它。那我该怎么做呢?
viewHeight.constant = max(0, min(45, scrollView.panGestureRecognizer.translationInView(scrollView.superview).y))
这应该使视图随手势移动,但最小值为 0,最大值为 45
使用 layoutIfNeeded()
属性 和 animateWithDuration
UIView.animateWithDuration(0.2, animations: { () -> Void in
viewHieght.constant = 45
self.view.layoutIfNeeded()
})