2016-03-02 3 views

ответ

4

попробовать это

На делегатом

func scrollViewDidEndDecelerating(scrollView: UIScrollView) { 
for cell in yourCollectionViewname.visibleCells() as [UICollectionViewCell] { 
    let indexPath = yourCollectionViewname.indexPathForCell(cell as UICollectionViewCell) 

    NSLog("%@", indexPath) 
} 
} 

Choice-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

Swift, безопасный способ, чтобы получить видимые детали:

if let indexPaths = self.collectionView.indexPathsForVisibleItems { 
    //Do something with an indexPaths array. 
} 
0

Вы можете использовать метод из UICollectionView как:

let indexPath = NSIndexPath(item: value1, section: value2) 
Смежные вопросы