答案 0 :(得分:3)
请检查这个库,它确实与你附加的gif做了什么。
另一种方式是你附加的gif文件。 在顶部添加搜索栏。并将隐藏部分作为标题并对齐搜索栏和tableview以获取该动画。
答案 1 :(得分:1)
您需要为滚动视图设置容器视图,并将要隐藏的视图设置为滚动视图的委托,注册此类以符合UIScrollViewDelegate协议。
您还需要跟踪滚动视图的内容偏移属性,并将setvthis设置为创建滚动视图时的初始偏移量:
fileprivate var scrollOffset : CGPoint
然后,正如您所说,使用scrollViewDidScroll方法:
internal func scrollViewDidScroll(_ scrollView: UIScrollView) {
let delta : CGPoint = CGPoint(x: scrollView.contentOffset.x - scrollOffset.x,
y: scrollView.contentOffset.y - scrollOffset.y)
if delta.y > 0, subviewToFade.isDescendant(of: self) {
// fade out subviews and remove
else if delta < 0, !subviewToFade.isDescendant(of: self) {
// add subviews and fade back in
}
scrollOffset = scrollView.contentOffset
}
希望有所帮助。
答案 2 :(得分:0)
我这样解决:
private var lastContentOffset: CGFloat = 0
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
self.lastContentOffset = scrollView.contentOffset.y
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if (self.lastContentOffset > scrollView.contentOffset.y) {
UIView.animate(withDuration: 0.25, animations: {
self.addDeviceButton.alpha = 1.0
self.addDeviceButton.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
}, completion: nil)
}
else if (self.lastContentOffset < scrollView.contentOffset.y) {
UIView.animate(withDuration: 0.25, animations: {
self.addDeviceButton.alpha = 0
self.addDeviceButton.transform = CGAffineTransform(scaleX: 1.3, y: 1.3)
}, completion: nil)
}
}
答案 3 :(得分:0)
func scrollViewDidScroll(_ scrollView: UIScrollView) {
setPosition(scrollView)
}
func setPosition(_ scrollView:UIScrollView) {
if scrollView.contentOffset.y >= 20 {
self.parentTopViewcontraints.constant = -95 // set postition till you want to hide your view
UIView.animate(withDuration: 0.5) {
self.view.layoutIfNeeded()
}
}else if scrollView.contentOffset.y <= 200 {
self.parentTopViewcontraints.constant = 0 //set back
UIView.animate(withDuration: 0.5) {
self.view.layoutIfNeeded()
}
}
}