gpt4 book ai didi

ios - 如何在应用启动时在 Collection View 中显示数组的中间元素?

转载 作者:行者123 更新时间:2023-11-28 06:01:15 24 4
gpt4 key购买 nike

谁能告诉我,当应用程序启动时,如何在 Collection View 中显示数组的中间元素,并且其他元素显示在这个中间元素的左侧和右侧?

最佳答案

viewDidLayoutSubviews 方法中,将您的 Collection View 滚动到特定的 IndexPath。并在启动时第一次使用 bool 变量。

var isFirstTime = true
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
if isFirstTime {
isFirstTime = false
let selectedIndex = IndexPath(item: 0, section: 0)
self.collectionView.scrollToItem(at: selectedIndex, at: .centeredHorizontally, animated: false)

}
}

关于ios - 如何在应用启动时在 Collection View 中显示数组的中间元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49646050/

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