Q
斯威夫特
7
A
回答
4
试试这个
在委托
func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
for cell in yourCollectionViewname.visibleCells() as [UICollectionViewCell] {
let indexPath = yourCollectionViewname.indexPathForCell(cell as UICollectionViewCell)
NSLog("%@", indexPath)
}
}
选择-2
上按钮单击
var point : CGPoint = sender.convertPoint(CGPointZero, toView:yourCollectionViewname)
var indexPath =yourCollectionViewname!.indexPathForItemAtPoint(point)
获得可见的所有物品
可以使用indexPathsForVisibleRows
返回的每个识别接收机可见行索引路径的数组。
- (NSArray的*)indexPathsForVisibleItems;
var visible: [AnyObject] = yourCollectionViewname.indexPathsForVisibleItems
var indexpath: NSIndexPath = (visible[0] as! NSIndexPath)
12
你试过委托功能?
public func indexPathsForVisibleItems() -> [NSIndexPath]
或
collectionView.indexPathsForVisibleItems()
这些都要给你你想要的东西。
1
斯威夫特,更安全的方式来获得可见的项目:
if let indexPaths = self.collectionView.indexPathsForVisibleItems {
//Do something with an indexPaths array.
}
0
可以使用UICollectionView的方法为:
let indexPath = NSIndexPath(item: value1, section: value2)
相关问题
- 1. 斯威夫特2斯威夫特3
- 2. 斯威夫特 - JSQMessagesViewController与斯威夫特
- 3. 斯威夫特
- 4. 斯威夫特
- 5. 斯威夫特
- 6. 斯威夫特
- 7. 斯威夫特
- 8. 斯威夫特
- 9. 斯威夫特
- 10. 斯威夫特
- 11. 斯威夫特
- 12. 斯威夫特
- 13. 斯威夫特
- 14. 斯威夫特
- 15. 斯威夫特
- 16. 斯威夫特
- 17. 斯威夫特
- 18. 斯威夫特
- 19. 斯威夫特
- 20. 斯威夫特
- 21. 斯威夫特
- 22. 斯威夫特
- 23. 斯威夫特
- 24. 斯威夫特
- 25. 斯威夫特
- 26. 斯威夫特CoreData
- 27. 在斯威夫特
- 28. PrepareForSegue斯威夫特
- 29. 斯威夫特:师
- 30. 斯威夫特3
要获取所有可见的细胞或特定的细胞 –