2017-03-16 39 views
2

我正在構建具有帖子提要的社交媒體應用程序。當帖子在屏幕上完全可見時,需要開始將已分配軌道播放到帖子。這是我現在的佈局。檢查UITableViewCell對於自動播放是否完全可見

Current layout, 2 items visible

這是一段代碼,我想通了,但它只是在一個時間軸上的第一個職位的工作。

func scrollViewDidScroll(_ scrollView: UIScrollView) { 
 
    
 
    let visibleCell = tableView.visibleCells.first as! HomeControllerTableViewCell 
 
    
 
    
 
    let firstCellVisibleIndexPath = tableView.indexPathsForVisibleRows?.first 
 
    
 
    
 
    if tableView.bounds.contains(tableView.rectForRow(at: firstCellVisibleIndexPath!)){ 
 
     let fullyVisibleCell = tableView.cellForRow(at: firstCellVisibleIndexPath!) as! HomeControllerTableViewCell 
 
     
 
     print(fullyVisibleCell.authorNameLabel.text) 
 
     
 
    } 
 
    
 
    }

請幫我找出如何確定哪些細胞是完全可見。

+0

你在第一個只測試:'tableView.visibleCells.first'。相反,讓allvisibleCells ='tableView.visibleCells',並做一個for循環。 – Larme

回答

0

這是我在決定如何結束什麼細胞是完全可見關於我的佈局

func scrollViewDidScroll(_ scrollView: UIScrollView) { 
 
    
 

 
    
 
    for item in tableView.indexPathsForVisibleRows!{ 
 
     if tableView.bounds.contains(tableView.rectForRow(at: item)){ 
 
     let fullyVisibleCell = tableView.cellForRow(at: item) as! HomeControllerTableViewCell 
 
     
 
     
 
    
 
     } 
 
    } 
 
    }

相關問題