-1

Scenario: I have a '>' button:

enter image description here

that is supposed to animate +90 degrees upon initial tap:

enter image description here

However after returning to the 0 degree '>' position via tapping on the UITableViewCell again which returns to its original height; then tapping AGAIN I get a further rotation to the '<' position:

enter image description here

How do I freeze the max rotation to only the 90 degrees (pointing down); so that I have the single +/- 90 deg rotation toggle?

Here's my code:

 func rotate2ImageView() {
        UIView.animate(withDuration: 0.3) {
            self.rightArrowImage.transform = self.rightArrowImage.transform.rotated(by: .pi / 2)
        }
    }

Here's a failed remedy (where I tried to remove all animations):

func rotateImageView(){
        UIView.animate(withDuration: 0.3, animations: {() -> Void in
            self.rightArrowImage.transform = self.rightArrowImage.transform.rotated(by: .pi / 2)
        }, completion: {(_ finished: Bool) -> Void in
            if finished {
               self.rightArrowImage.layer.removeAllAnimations()
            }
        })
    }

Frederick C. Lee
  • 9,019
  • 17
  • 64
  • 105
  • "However after returning to the 0 degree '>' position" Please show the code where you do that. It should involve setting the `transform` to `.identity`. – matt Apr 24 '19 at 18:26
  • I don't have code. I merely tap again and the UITableViewCell's height returns to its original size..... and the '>' icon returns to its original state. – Frederick C. Lee Apr 24 '19 at 20:54
  • Well, you have shown no code about tapping or changing cell height. But you just implied it exists. So you do have code. Show it. – matt Apr 24 '19 at 21:02
  • You gave me the hint. I solved its! – Frederick C. Lee Apr 24 '19 at 21:13

1 Answers1

0

I needed to reset the '>' image's transformation prior to future taps to rotate the icon.
I did this via setting its transformation to 'identity' per Matt's suggestion.

 func rotateImageView() {
        // Reset any pending transformation to original status:
        rightArrowImage.transform = .identity

        UIView.animate(withDuration: 0.3) {
            self.rightArrowImage.transform = self.rightArrowImage.transform.rotated(by: .pi / 2)
        }
    }

This is fired every via the UITableViewDelete's willDisplay function:

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        let myCell = cell as? CommonFAQCell
        if expandCell {
            myCell?.rotateImageView()
        }
    }
Frederick C. Lee
  • 9,019
  • 17
  • 64
  • 105