Skip to content

Instantly share code, notes, and snippets.

@jeantimex
Last active July 19, 2017 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeantimex/b8933bf78007dbf0641c92b72c57a629 to your computer and use it in GitHub Desktop.
Save jeantimex/b8933bf78007dbf0641c92b72c57a629 to your computer and use it in GitHub Desktop.
GestureRecognizer
protocol CollapsibleTableViewHeaderDelegate {
func toggleSection(header: CollapsibleTableViewHeader, section: Int)
}
class CollapsibleTableViewHeader: UITableViewHeaderFooterView {
var delegate: CollapsibleTableViewHeaderDelegate?
var section: Int = 0
...
override init(reuseIdentifier: String?) {
super.init(reuseIdentifier: reuseIdentifier)
...
addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(CollapsibleTableViewHeader.tapHeader(_:))))
}
...
func tapHeader(gestureRecognizer: UITapGestureRecognizer) {
guard let cell = gestureRecognizer.view as? CollapsibleTableViewHeader else {
return
}
delegate?.toggleSection(self, section: cell.section)
}
func setCollapsed(collapsed: Bool) {
// Animate the arrow rotation (see Extensions.swf)
arrowLabel.rotate(collapsed ? 0.0 : .pi / 2)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment