我有一个UICollectionView
在一个UIViewController
启用分页。由于某种奇怪的原因 collectionView.scrollToItem
工作时的方向collectionview
is vertical
但当方向为horizontal
。这是我做错了什么还是应该发生这种情况?
//Test scrollToItem
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let i = IndexPath(item: 3, section: 0)
collectionView.reloadData()
collectionView.scrollToItem(at: i, at: .top, animated: true)
print("Selected")
}
适用于 iOS 14
显然有一个新的错误UICollectionView
这导致scrollToItem
启用分页时不起作用。解决方法是在调用之前禁用寻呼scrollToItem
,然后重新启用它:
collectionView.isPagingEnabled = false
collectionView.scrollToItem(
at: IndexPath(item: value, section: 0),
at: .centeredHorizontally,
animated: true
)
collectionView.isPagingEnabled = true
Source: https://developer.apple.com/forums/thread/663156 https://developer.apple.com/forums/thread/663156
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)