选择单元格时 UICollectionView 正在滚动 [英] UICollectionView is scrolling when selecting a cell

查看:27
本文介绍了选择单元格时 UICollectionView 正在滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在 UICollectionView 中选择一个项目时遇到问题,因为当我点击它时它会滚动一点.

我知道 didSelectItemAtIndexPath 正在被调用,但我想在选择时防止滚动.我只希望集合视图在用户滚动时滚动,但如果用户只是点击单元格,它不应该移动.仅应选择.

我不知道如何预防这个问题,希望你能帮助我.

任何帮助将不胜感激.

解决方案

如果您使用 collectionview.selectItem(at: indexpath, animation: true, scrollPosition: .top) 以编程方式选择单元格- 由于您没有与我们分享您的任何代码,让我们假设这是正确的...

...然后像我一样你可能没有意识到你可以使用这样的空集:collectionview.selectItem(at: indexpath, animation: true, scrollPosition: [])>

I'm having trouble when i try to select an item inside a UICollectionView since when I click on it it scrolls a little bit.

I know didSelectItemAtIndexPath is being called but I want to prevent the scrolling when selecting. I only want the collection view to scroll when the user is scrolling through but if the user is just tapping the cell it shouldn't move. Only should be selected.

I hope you can help me since I don't know how to prevent this problem.

Any help will be really appreciated.

解决方案

If you are selecting the cell programmatically with collectionview.selectItem(at: indexpath, animated: true, scrollPosition: .top) -- and since you didn't share any of your code with us, let's assume that's correct...

... then like me you might not have realized that you can use an empty set like this: collectionview.selectItem(at: indexpath, animated: true, scrollPosition: [])

这篇关于选择单元格时 UICollectionView 正在滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆