Monday, September 21, 2026
HomeiOS Developmentios - UIImageView fallacious rotation utilizing CGAffineTransform

ios – UIImageView fallacious rotation utilizing CGAffineTransform

[ad_1]

I’ve 4 sections, every part have 2 nested rows. I open the rows by tapping on every part.

After I faucet on a piece I would like it accent (chevron.proper, made as UIImageView) be rotated clockwise by 90 levels with a easy animation and once I click on once more on the identical part – rotate again, counterclockwise by 90 levels.

I’ve a variable referred to as isOpened (bool, false by default), which I alter from false to true and again every faucet in didSelectRowAt. Primarily based on {that a} present all nested cells:

   override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
      if indexPath.row == 0 {
        sections[indexPath.section].isOpened = !sections[indexPath.section].isOpened
        tableView.reloadSections([indexPath.section], with: .none)
      }
   }

In the identical technique I attempt to rotate the chevron:

    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    if indexPath.row == 0 {
        sections[indexPath.section].isOpened = !sections[indexPath.section].isOpened
        tableView.reloadSections([indexPath.section], with: .none)
        
        guard let cell = tableView.cellForRow(at: indexPath) as? MainSortTableViewCell else { return }

        if sections[indexPath.section].isOpened {
            UIView.animate(withDuration: 1.0) {
                cell.chevronImage.rework = CGAffineTransform(rotationAngle: .pi/2)
            }
        } else {
            UIView.animate(withDuration: 1.0) {
                cell.chevronImage.rework = CGAffineTransform(rotationAngle: -.pi/2)
            }
        }
     }

However with this strategy I face a few issues:

  1. Whereas first faucet it animates chevron down on 90 levels as I want, however once I faucet once more – it rotates preliminary chevron (face to the proper) which causes a outcome as chevron seems up as a substitute (-pi/2). Find out how to repair the behaviour and rotate chevron from its new place (from when its face is down again to preliminary proper)?
  2. When I attempt to faucet after first rotation the animation shall be by no means triggered once more. The transition is speedy. Find out how to repair that?

Here’s a GIF with the issue behaviour: CLICK

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments