问题:
ios 如何显示类似文字copy & 粘贴那样的 上下文菜单
解决:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
class MyViewController : UIViewController{ //MARK: menu func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { self.becomeFirstResponder() //important!! let menuc = UIMenuController.shared let cell = collectionView.cellForItem(at: indexPath)! menuc.setTargetRect(cell.bounds, in: cell) menuc.menuItems = [UIMenuItem(title:"report", action:#selector(report) )] menuc.update() menuc.setMenuVisible(true, animated: true) } func report(){ ... } override var canBecomeFirstResponder: Bool{ return true } override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool { let ret = action == #selector(report) return ret } .... } |
参考:
http://blog.csdn.net/iosworker/article/details/50721731