ios - (Swift) Deleting UITableViewCell by dragging it out of the UITableView? -
i have uitableview
items array in it. it's possible move position of uitableviewcell
anuilongpressgesturerecognizer
freely around y , x axis, want able delete dragged uitableviewcell
if it's moved outside of uitableview
.
i'm aware i'll using switch caseuigesturerecognizer.ended
perform i'm @ loss on how deal it.
here's code:
func longpressgesturerecognized(gesturerecognizer: uigesturerecognizer) { let longpress = gesturerecognizer as! uilongpressgesturerecognizer let state = longpress.state var locationinview = longpress.locationinview(tbltasks) var indexpath = tbltasks.indexpathforrowatpoint(locationinview) struct { static var cellsnapshot: uiview? = nil } struct path { static var initialindexpath : nsindexpath? = nil } switch state { case uigesturerecognizerstate.began: if indexpath != nil { path.initialindexpath = indexpath let cell = tbltasks.cellforrowatindexpath(indexpath!) uitableviewcell! my.cellsnapshot = snapshotofcell(cell) var center = cell.center my.cellsnapshot!.center = center my.cellsnapshot!.alpha = 0.0 tbltasks.addsubview(my.cellsnapshot!) uiview.animatewithduration(0.25, animations: { () -> void in center.y = locationinview.y my.cellsnapshot!.center = center my.cellsnapshot!.transform = cgaffinetransformmakescale(1.05, 1.05) my.cellsnapshot!.alpha = 0.98 cell.alpha = 0.0 }, completion: { (finished) -> void in if finished { cell.hidden = true } }) // end of animation sequence } // end of if statement case uigesturerecognizerstate.changed: var center = my.cellsnapshot!.center center.x = locationinview.x center.y = locationinview.y my.cellsnapshot!.center = center if (indexpath != nil) && (indexpath != path.initialindexpath) { swap(&taskmgr.tasks[indexpath!.row], &taskmgr.tasks[path.initialindexpath!.row]) tbltasks.moverowatindexpath(path.initialindexpath!, toindexpath: indexpath!) path.initialindexpath = indexpath } default: let cell = tbltasks.cellforrowatindexpath(path.initialindexpath!) uitableviewcell! cell.hidden = false cell.alpha = 0.0 uiview.animatewithduration(0.25, animations: { () -> void in my.cellsnapshot!.center = cell.center my.cellsnapshot!.transform = cgaffinetransformidentity my.cellsnapshot!.alpha = 0.0 cell.alpha = 1.0 }, completion: { (finished) -> void in if finished { path.initialindexpath = nil my.cellsnapshot!.removefromsuperview() my.cellsnapshot = nil } }) } // end of switch } // end of longpressgesturerecognized func
any ideas?
you're on right track need embed table view controller in container of view controller, , put gesture recognizer code in container view controller.
this lot: http://www.freshconsulting.com/create-drag-and-drop-uitableview-swift/
it's not 100% right pretty close , able use going.
Comments
Post a Comment