简体   繁体   English

如何设置 collectionView 位置?

[英]How do I set the collectionView position?

I have a UICollectionView build like in the picture.我有一个UICollectionView构建,如图所示。 For example, I choose the 5th button and closed and opened the application.例如,我选择第 5 个按钮并关闭并打开应用程序。 I want the 5th button to appear on the screen when the application is opened again.当再次打开应用程序时,我希望第 5 个按钮出现在屏幕上。 In other words, the UICollectionView should not return to the first position when the application is opened again.换句话说,当再次打开应用程序时, UICollectionView不应返回到第一个位置。

https://i.hizliresim.com/mxX5qT.png https://i.hizliresim.com/mxX5qT.png

You can use this at your collection view's didSelectItem func :您可以在集合视图的didSelectItem func 中使用它:

collectionView.scrollToItem(at: indexPath, at: .left, animated: true)

Hope it helps...希望能帮助到你...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM