ios - Reordering cell interactively with resized imageView -
i want able reorder cells in collectionview have cell moving's image scaled down smaller size duration of reorder. able cell resize while moving there issue when cell crosses on cell , attempts reorder. @ moment cell reaches cell, temporarily resizes normal size, causing flickering when moving around.
i have followed this blog description using apple's methods interactively reorder cells in uicollectionview. methods using listed under "reordering items interactively" section of this page.
i have uicollectionview subclass, uicollectionviewcell subclass, , extensions uicollectionviewdelegateflowlayout, uicollectionviewdatasource, , uicollectionviewdelegate.
the way resizing cell adding boolean cell's subclass set false default true when beginning , updating cell movement, , false when ending or canceling. in sizeforitem method uicollectionviewdelegateflowlayout extension, checking boolean , returning size accordingly.
it has been difficult debug methods getting size display when cell's image returns normal size split second, causing flickering behavior, each method called many times update movement smoothly.
i not married resizing cell in way, if cause of issue, i'm not sure how resize , prevent flickering when crossing on other cells in collectionview.
thank in advance suggestions.
update code samples.
i update size of bounds of imageview in begininteractivemovementforitem shrink initially. time collectionview calls update method, size gets reset, cell gets size sizeforitem, below logic that.
as side note, have tried resizing bounds of cell in begininteractivemovement in addition imageview's bounds, had no effect removed that.
here's how i'm handling resizing imageview:
in collection view's parent:
@objc func handlelonggesture(_ sender: uilongpressgesturerecognizer) { switch(sender.state) { case .began: let location = sender.location(in: self.collectionview) guard let selectedindexpath = self.collectionview.indexpathforitem(at: location) else { return } guard let dragcell = collectionview.cellforitem(at: selectedindexpath) as? activityphotogallerycell else { return } uiview.animate(withduration: 0.17, animations: { dragcell.center = location }) collectionview.begininteractivemovementforitem(at: selectedindexpath) case .changed: collectionview.updateinteractivemovementtargetposition(sender.location(in: sender.view)) case .ended: collectionview.endinteractivemovement() default: collectionview.cancelinteractivemovement() } } in collection view subclass:
override func begininteractivemovementforitem(at indexpath: indexpath) -> bool { guard let dragcell = cellforitem(at: indexpath) as? customcellobject else { return false } draggingcell = dragcell dragcell.isdragging = true return super.begininteractivemovementforitem(at: indexpath) } and here size item logic:
var sizeforitem = cgsize(width: widthperitem, height: widthperitem) let cell = collectionview.cellforitem(at: indexpath) as? customcellobject if (cell?.isdragging ?? false) { sizeforitem.height *= 0.7 sizeforitem.width *= 0.7 } return sizeforitem
Comments
Post a Comment