UICollectionView不会滚动到indexPath [英] UICollectionView is not scrolling to indexPath

查看:91
本文介绍了UICollectionView不会滚动到indexPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UICollectionView,我将translatesAutoresizingMaskIntoConstraints设置为NO,并添加了一些约束。当我尝试将其滚动到indexPath时:

I have a UICollectionView that I set the translatesAutoresizingMaskIntoConstraints to NO, and added some constraints. When I try scrolling it to an indexPath:

[self.datesCollectionView selectItemAtIndexPath:selectedCellIndexPath animated:YES scrollPosition:UICollectionViewScrollPositionCenteredHorizontally];



然后它完全忽略它,并且不滚动。但是当我删除translatesAutoresizingMaskIntoConstraints时,它会滚动,但会忽略约束。



我的问题是,当translatesAutoresizingMaskIntoConstraints是什么时,如何让collectionView滚动到indexPath?设置为NO?


Then it completely ignores that, and doesn't scroll. But when I remove translatesAutoresizingMaskIntoConstraints, then it scrolls, but the constraints are ignored.

My question is, How can I get the collectionView to scroll to an indexPath when translatesAutoresizingMaskIntoConstraints is set to NO?

推荐答案

您有一些自动布局问题。观看WWDC会议Autolayout第2部分之谜,了解您需要改变的内容。 translatesAutoresizingMaskIntoConstraints应该是NO。



滚动工作正常,但要注意只有所选单元格才能显示。如果部分可见没有任何反应因此,您可能需要一些额外的逻辑来执行您想要的操作。
You have some autolayout issue. Watch the WWDC Session "Mystery of Autolayout Part 2" to understand what you need to change. translatesAutoresizingMaskIntoConstraints should be NO.

The scrolling works fine, but be aware that only the selected cell gets simply shown. if partly visible nothing happens. So you may need some additional logic to do what you want.


这篇关于UICollectionView不会滚动到indexPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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