[英]How to hide a UIView(Collection view) while scrolling the UITableview?
I am trying to slide up the upper view(Collection view), as the user scrolls up the tableview,and reveal it as the user scrolls down.当用户向上滚动表格视图时,我试图向上滑动上视图(集合视图),并在用户向下滚动时显示它。 I do not know how to go about this.我不知道如何 go 关于这个。 I have tried looking as the scrollView didScroll function, but I am lost as how to set this up.我尝试过查看scrollView didScroll function,但我不知道如何设置它。 Any advice?有什么建议吗?
UITableViewDelegate
also serves UIScrollViewDelegate
as you can see in the documentation:正如您在文档中看到的那样, UITableViewDelegate
还提供UIScrollViewDelegate
服务:
public protocol UITableViewDelegate : UIScrollViewDelegate
Try this:尝试这个:
override func scrollViewDidScroll(_ scrollView: UIScrollView) {
if(scrollView.panGestureRecognizer.translation(in: scrollView.superview).y > 0)
{
print("scrolled up")
//show the collection view here
}
else
{
print("scrolled down")
//hide the collection view here
}
}
In case you want to slide the collectionView instead of hiding it as you said in the comment below, I suggest you to follow this answer: https://stackoverflow.com/a/38597530/13839521如果您想滑动 collectionView 而不是像您在下面的评论中所说的那样隐藏它,我建议您遵循以下答案: https://stackoverflow.com/a/38597530/13839521
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.