Skip to content

Instantly share code, notes, and snippets.

@odrobnik
Last active September 6, 2016 13:32
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 odrobnik/0e3d4b51e7b29fa9a874cc013cebd86e to your computer and use it in GitHub Desktop.
Save odrobnik/0e3d4b51e7b29fa9a874cc013cebd86e to your computer and use it in GitHub Desktop.
import UIKit
class TableSectionFooterView: UIView
{
var section: Int = 0
var limitMovementToUpwards: Bool = false
override var frame: CGRect
{
set(newValue)
{
if newValue.origin.y >= frame.origin.y && limitMovementToUpwards
{
return
}
super.frame = newValue
}
get
{
return super.frame
}
}
}
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath)
{
if editingStyle == .Delete
{
tableView.subviews.forEach({ (subview) in
if let subview = subview as? TableSectionFooterView
{
subview.setNeedsLayout()
subview.limitMovementToUpwards = true
}
})
removeListItem(at: indexPath)
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
tableView.subviews.forEach({ (subview) in
if let subview = subview as? TableSectionFooterView
{
subview.setNeedsLayout()
subview.limitMovementToUpwards = false
}
})
UIView.animateWithDuration(0.20, delay: 0, options: [.BeginFromCurrentState, .CurveLinear], animations: {
tableView.setNeedsLayout()
tableView.layoutIfNeeded()
}, completion: nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment