Swift - 在后台推送 CollectionView

Swift - Push CollectionView in the background

如何以编程方式在后台推送我的 collectionView?现在它覆盖了我的底栏。在情节提要中很容易,但我不知道如何以编程方式完成它。

    let theCollectionView: UICollectionView = {
    let v = UICollectionView(frame: CGRect.zero, collectionViewLayout: UICollectionViewFlowLayout())
    v.translatesAutoresizingMaskIntoConstraints = false
    v.backgroundColor = .white
    v.contentInsetAdjustmentBehavior = .always
    v.layer.cornerRadius = 30
    return v
}()

使用

self.view.sendSubviewToBack(_ with: UIView)

方法如果我解决了你的问题并且在集合视图后面有另一个视图。

因此,例如,您的视图具有 DashboardController 等的视图。因此,在您希望的块中,您必须

self.view.sendSubviewToBack(theCollectionView)

希望对您有所帮助。

要实现这一目标还有一些工作要做。

您可以隐藏您的 collectionView

yourCollectionView.isHidden = true

您可以从 superview

中删除您的 UICollectionView
   yourCollectionView.removeFromSuperView()

或者您可以将 UICollectionView 设为 Optional

然后你可以removeFromSuperView并设置nil.

yourCollectionView.removeFromSuperView()
yourCollectionView = nil

然后可以设置nilremoveFromSuperView

再次使用时,必须重新初始化。