2017-01-22 57 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