UIImageView旋转UITableViewCell里面的动画
我想旋转选择row 0
的UIImage视图。选择该部分需要重新加载以添加两个单元格。这是动画无法工作的地方。 imageview只是转换到新位置而不执行动画。UIImageView旋转UITableViewCell里面的动画
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath) as! CustomTableViewCell
if indexPath.row == 0 {
print(cell)
}
if displayCell {
UIView.animate(withDuration:0.3, animations: {
cell.rotateButtonImageView.transform = CGAffineTransform(rotationAngle: CGFloat(0))
})
if indexPath.row != 0 {
swap(&indexArr[indexPath.row], &indexArr[0])
print(indexArr)
}
} else {
UIView.animate(withDuration: 0.3, animations: {
cell.rotateButtonImageView.transform = CGAffineTransform(rotationAngle: (180.0 * .pi)/180.0)
})
}
displayCell = !displayCell
tableView.reloadSections(IndexSet(integersIn: 0...0), with: .none)
}
此外,特定的单元格在行= 0时,内容需要更新。 这里是一个sample项目:
你需要你的动画后,重新加载您UITableView
节将在
您还需要修改cellForRow方法
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CustomTableViewCell") as! CustomTableViewCell
switch indexPath.section {
case 0:
cell.rotateButtonImageView.isHidden = indexPath.row != 0 || indexArr.count <= 2
if(indexPath.row == 0)
{
if displayCell{
cell.rotateButtonImageView.transform = CGAffineTransform(rotationAngle: (180.0 * .pi)/180.0)
}else{
cell.rotateButtonImageView.transform = .identity
}
}
break
default :
cell.rotateButtonImageView.isHidden = true
break
}
cell.indexLabel.text = indexArr[indexPath.row].0
return cell
}
使用此代码为您didSelectRowAt
方法
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath) as! CustomTableViewCell
if indexPath.row == 0 {
print(cell)
}
if displayCell {
cell.rotateButtonImageView.transform = CGAffineTransform(rotationAngle: (180.0 * .pi)/180.0)
UIView.animate(withDuration: 0.3, animations: {
cell.rotateButtonImageView.transform = CGAffineTransform(rotationAngle: CGFloat(0))
}, completion: { (finished) in
tableView.reloadSections(IndexSet(integersIn: 0...0), with: .automatic)
})
if indexPath.row != 0 {
swap(&indexArr[indexPath.row], &indexArr[0])
print(indexArr)
}
} else {
cell.rotateButtonImageView.transform = CGAffineTransform(rotationAngle: CGFloat(0))
UIView.animate(withDuration: 0.3, animations: {
cell.rotateButtonImageView.transform = CGAffineTransform(rotationAngle: (180.0 * .pi)/180.0)
}, completion: { (finished) in
tableView.reloadSections(IndexSet(integersIn: 0...0), with: .automatic)
})
}
displayCell = !displayCell
}
希望这有助于
感谢您的输入,但我尝试了这一点,但没有帮助 –
@SiddharthanAsokan我的答案再次更新,我将发布带有结果的gif –
太棒了〜 –
它是什么,是无法精确地工作? – ozgur
我已经更新了问题 –