Last active
July 19, 2017 19:02
-
-
Save jeantimex/b8933bf78007dbf0641c92b72c57a629 to your computer and use it in GitHub Desktop.
GestureRecognizer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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