ios - How to show MenuController of UICollectionViewCell? -
how reproduce copy paste function of say, messages on iphone, if long press on message, message cell goes gray-ish , little pop-up "copy" shows up. how can show same menu on uicollectionviewcells?
as turns out functionality built in , simple implementing 3 collectionview:
delegate methods. created protocol copyablecell
property called copyableproperty
, string cell wants copy clipboard, cells can copy must follow. straightforward on:
func collectionview(collectionview: uicollectionview, shouldshowmenuforitematindexpath indexpath: nsindexpath) -> bool { if let _ = collectionview.cellforitematindexpath(indexpath) as? copyablecell { return true } return false } func collectionview(collectionview: uicollectionview, canperformaction action: selector, foritematindexpath indexpath: nsindexpath, withsender sender: anyobject?) -> bool { if action.description == "copy:" { return true } return false } func collectionview(collectionview: uicollectionview, performaction action: selector, foritematindexpath indexpath: nsindexpath, withsender sender: anyobject?) { //no more checking needed here since allow copying if let cell = collectionview.cellforitematindexpath(indexpath) as? copyablecell { uipasteboard.generalpasteboard().string = cell.copyableproperty } }
Comments
Post a Comment