Home Multi selection table view - Rotate image in custom header when section expands/collapses
Reply: 0

Multi selection table view - Rotate image in custom header when section expands/collapses

user1565
1#
user1565 Published in July 15, 2018, 9:10 pm

Problem: When a section is expanded, the arrow in the section header rotates to point up. When I tap a cell, the arrow starts pointing down & rotates clockwise to point up (the arrow "twitches").

How do I get rid of the arrow's "twitch"? I want the arrow to point up when the section is expanded and point down when the section is collapsed.

CollapsibleFilterTableViewHeader

func setExpanded(expanded: Bool) {
    //Get angle of arrow (0.0 for pointing up or 180.0 for pointing down)
    let rad: Double = atan2( Double(arrowImageView.transform.b), Double(arrowImageView.transform.a))
    let deg: CGFloat = CGFloat(rad) * (CGFloat(180) / CGFloat.pi )

    if (expanded && deg == 0.0) {
        arrowImageView.rotate(.pi)
    }
}

FiltersViewController

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        header.setExpanded(expanded: filterSection.isExpanded)
        header.delegate = self
        return header
    }

func toggleSection(header: CollapsibleFilterTableViewHeader, section: Int) {
        let isExpanded = !filterSection.isExpanded

        // Toggle isExpanded
        filterSection.isExpanded = isExpanded
        header.setExpanded(expanded: isExpanded)

        filtersTableView.reloadSections(NSIndexSet(index: section) as IndexSet, with: .automatic)
    }

Sources: Stackoverflow Question, Medium Article

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.305451 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO