gpt4 book ai didi

ios - 将 Collection View 滚动到顶部

转载 作者:行者123 更新时间:2023-11-30 12:07:23 25 4
gpt4 key购买 nike

我有以下 Collection View 。当用户向上 ScrollView 时,我希望 Collection View 一直向上滚动。同样,当它向下滚动时,我希望它回到原来的位置。

我在collectionview上面有一个uiview和imageView。

enter image description here

现在,如果这是一个表格 View ,我会使用标题。我如何实现这种行为。我没主意了。

提前致谢

最佳答案

UICollectionViewUIScrollView 的子类,因此您只需通过 ScrollView delegate 方法和约束即可实现您想要的UICollectionView 上的 UIViewUIImageView

在这里,我将向您提供一个使用 ScrollView 委托(delegate)来实现这一目标的示例。

func scrollViewDidScroll(_ scrollView: UIScrollView) {
if scrollView == collectionView{
if scrollView.contentOffset.y == 0{
UIView.animate(withDuration: 0.5) { () -> Void in
self.constTopTagHeight.constant = 175 // Your UIView and imageview constraints adjust.
self.view.layoutIfNeeded()
}
}
else{
UIView.animate(withDuration: 0.5) { () -> Void in
self.constTopTagHeight.constant = 0 // Your UIView and imageview constraints adjust.
self.view.layoutIfNeeded()
}
}
}
}

希望这对您有帮助。

关于ios - 将 Collection View 滚动到顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46511058/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com