//BCmessageCell文件代码
typealias BCChatCellAuxiliarytypeBlock = (cell:BCMessageCell,message:ArrowIMMessage,type:BCChatCellType)->Void
var _auxiliaryBlock:BCChatCellAuxiliarytypeBlock?
func longpressBubbleView(){
self.becomeFirstResponder()
let menuController = UIMenuController.sharedMenuController()
let menuItem_1 = UIMenuItem.init(title: "复制", action: Selector("copyChatMessage"))
// let menuItem_2 = UIMenuItem.init(title: "删除", action: Selector("deleteChatMessage"))
// let menuItem_3 = UIMenuItem.init(title: "收藏", action: Selector("saveChatMessage"))
// let menuItem_4 = UIMenuItem.init(title: "转发", action: Selector("deliverChatMessage"))
menuController.menuItems = [menuItem_1]
menuController.setTargetRect((bubbleView?.frame)! , inView: self)
menuController.setMenuVisible(true, animated: false)
// delegate?.longPressBubbleView!(messageModel!)
}
func copyChatMessage(){
if ((_auxiliaryBlock) != nil){
_auxiliaryBlock!(cell: self,message: (self.messageModel?.message)!,type: .BCChatCellCopyStyle)
}
}
func setAuxiliarytypeBlock(auxiliarytypeBlock:BCChatCellAuxiliarytypeBlock){
_auxiliaryBlock = auxiliarytypeBlock
}
override func canBecomeFirstResponder()->Bool
{
return true
}
override func canPerformAction(action: Selector, withSender sender: AnyObject?) -> Bool {
return action == Selector("copyChatMessage")
}
//BCMessageViewController代码
写在func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 代理中
cell?.setAuxiliarytypeBlock({ (cell, message, type) -> Void in
switch(type){
case .BCChatCellCopyStyle:
let pasterBoard = UIPasteboard.generalPasteboard()
switch (message.messageFormat){
case .Text:
pasterBoard.string = message.context
case .Image: break
case .Audio: break
case .Video: break
case .File: break
case .Json: break
case .Location: break
case .At:
pasterBoard.string = message.context
default:break
}
case .BCChatCellDeleteStyle:break
case .BCChatCellCollectionStyle:break
case .BCChatCellDeliverStyle:break
case .BCChatEarPhoneStyle:break
}
})
原文:http://www.cnblogs.com/torrescx/p/5345786.html