我正在尝试对单元格中的 UIImageView
使用核心动画。我不确定如何访问单元格或 UIImageView
。
我使用的是 swift 5。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath) as! CountryListCell
cell.accessoryType = .disclosureIndicator
let str = factsJsonList[indexPath.row].country
let image = UIImage(named: str)
cell.flagImageView.image = image
cell.flagNameLabel.text = str.uppercased()
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = [tableView.cellForRow(at: indexPath)]
// TODO :core animate the image view
let vc = CountryFactListVC()
vc.country = factsJsonList[indexPath.row]
navigationController?.pushViewController(vc, animated: true)
}
最佳答案
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
//access the current cell
guard let cell = tableView.cellForRow(at: indexPath) as? CountryListCell
else{
return
}
// TODO :core animate the image view
let imageViewToAnimate = cell.flagImageView //you can use this object to animate image view of cell
}
关于ios - 如何从 didSelectRowAtindexPath : function 访问单元格 imageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55487756/