2017-01-22 63 views
0

我在swift 3的tvOS項目中爲我的桌面視圖提供了此代碼,當滾動它時,我想要顏色單元格不聚焦!請能解釋一下怎麼做?在適用的滾動單元格中更改焦點和顏色

我的代碼

func numberOfSections(in tableView: UITableView) -> Int { 
 
    return 1 
 
} 
 
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
 
    return tvChannelsArray.count 
 
} 
 
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
 
    let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) 
 
    
 
    // Show TV Channels names 
 
    cell.textLabel?.text = ((tvChannelsArray[(indexPath as NSIndexPath).row] as AnyObject).object(forKey: "channel") as! String) 
 
    
 
    cell.imageView?.image = UIImage(named: "\(cell.textLabel!.text!)") 
 
    
 
return cell 
 
} 
 
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 
 
    channelsTableView.isHidden = false; 
 

 
    return 100 
 
    
 
}

回答

0

在你的tableview委託執行UISsrollViewDelegate方法ScrollViewDidScroll

func scrollViewDidScroll(_ scrollView: UIScrollView) { 
     for cell in tableView.visibleCells { 
      if let currentCellPath = tableView.indexPath(for: cell), 
       let selectedCellPath = tableView.indexPathForSelectedRow { 
       guard currentCellPath != selectedCellPath else { 
        continue 
       } 
      } 
      let red = Float(cell.frame.origin.y/scrollView.contentSize.height) 
      cell.contentView.backgroundColor = UIColor(colorLiteralRed: red, green: 0.5, blue: 0.25, alpha: 1) 
     } 
    } 
+0

的tableView說沒有找到如何改變呢? – user1178728