2017-08-16 3 views
2

Ich versuche, eine UIImage-Ansicht zu drehen, indem ich row 0 auswähle. Bei der Auswahl muss dieser Abschnitt neu geladen werden, um zwei weitere Zellen hinzuzufügen. Hier funktioniert die Animation nicht. Die Bildansicht wird nur an die neue Position transformiert, ohne die Animation auszuführen.UIImageView Animation in UITableViewCell drehen

 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) 
    } 

Auch diese bestimmte Zelle bei Zeile = 0, muss der Inhalt aktualisiert werden. Hier ist ein sample Projekt:

+0

was ist es, genau arbeiten versagt? – ozgur

+0

Ich habe die Frage aktualisiert –

Antwort

2

Sie benötigen UITableView Abschnitte nach Ihrer Animationen nachladen über

Sie auch benötigen cellForRow Methode

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 

    } 

Verwenden Sie diesen Code für Ihre didSelectRowAt Methode ändern

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 
} 

enter image description here

hoffe, das hilft

+0

Vielen Dank für Ihre Eingabe, aber ich habe versucht, und es hat nicht geholfen –

+0

@SiddharthanAsokan meine Antwort wurde wieder aktualisiert, ich potif gif mit Ergebnissen –

+0

Great ~ das hat funktioniert –