Skip to content

Instantly share code, notes, and snippets.

@WikipediaBrown
Created August 1, 2016 23:56
Show Gist options
  • Save WikipediaBrown/9279b79fc5383fe9a7d13d65835bb961 to your computer and use it in GitHub Desktop.
Save WikipediaBrown/9279b79fc5383fe9a7d13d65835bb961 to your computer and use it in GitHub Desktop.
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell = receiptsTableView.dequeueReusableCellWithIdentifier("receiptCell", forIndexPath: indexPath) as! ReceiptTableViewCell
switch selectedRow {
case nil:
selectedRow = indexPath
receiptIsOpen = true
cellVarticalPosition = receiptsTableView.contentOffset.y
default:
if selectedRow! == indexPath {
selectedRow = nil
receiptIsOpen = false
} else {
selectedRow = indexPath
receiptIsOpen = true
}
}
if receiptIsOpen == false {
receiptsTableView.scrollEnabled = true
UIView.animateWithDuration(0.2, animations: {
self.navigationBar.alpha = 1.0
self.receiptsTableView.center.y += self.navigationBar.frame.height
self.receiptsTableView.frame.size.height -= self.navigationBar.frame.height
})
tableView.contentOffset.y = cellVarticalPosition
} else {
receiptsTableView.scrollEnabled = false
UIView.animateWithDuration(0.2, animations: {
self.navigationBar.alpha = 0.0
self.receiptsTableView.center.y -= self.navigationBar.frame.height
self.receiptsTableView.frame.size.height += self.navigationBar.frame.height
})
}
tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .None)
if receiptIsOpen != false {
receiptsTableView.scrollToRowAtIndexPath(selectedRow!, atScrollPosition: .Top, animated: true)
cell.animateEdgeView()
reloadInputViews()
} else {
cell.reverseAnimateWithDuration()
reloadInputViews()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment