禁用uicollectionview滚动会使uicollectionview变小

时间:2017-08-04 10:13:23

标签: ios swift

我有uicollectionview

let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
layout.minimumLineSpacing = 90
collectionView = UICollectionView(frame: CGRect(x:0,y:0,width:0,height:0), collectionViewLayout: layout)
collectionView.translatesAutoresizingMaskIntoConstraints = false
collectionView.isScrollEnabled = false 

collectionView.heightAnchor.constraint(equalToConstant: collectionView.contentSize.height).isActive = true        collectionView.topAnchor.constraint(equalTo:PostsTab.bottomAnchor).isActive = true
collectionView.centerXAnchor.constraint(equalTo: scrollView.centerXAnchor).isActive = true
collectionView.widthAnchor.constraint(equalTo: scrollView.widthAnchor).isActive = true
collectionView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor).isActive = true

现在这个collectionView位于scrollView内。在collectionview之上还有另一个视图,它看起来都像这样

What i want to do is

现在,当我向下滚动时,我希望UIView位于collectionView之上,这就是为什么我添加isScrollEnabled = false的原因,当我向下滚动uiview时保持在固定位置

像这样enter image description here

override func viewDidAppear(_ animated: Bool) {
    scrollView.contentSize = CGSize(width:1,height: 2400)
    collectionView.heightAnchor.constraint(equalToConstant: collectionView.contentSize.height).isActive = true
}

0 个答案:

没有答案