tap to show copy menu
This commit is contained in:
parent
5a0b97b22f
commit
67570256d0
3 changed files with 38 additions and 5 deletions
|
|
@ -13,6 +13,12 @@ class LabelTableViewCell: UITableViewCell {
|
|||
@IBOutlet weak var contentLabel: UILabel!
|
||||
@IBOutlet weak var titleLabel: UILabel!
|
||||
|
||||
override var canBecomeFirstResponder: Bool {
|
||||
get {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
override func awakeFromNib() {
|
||||
super.awakeFromNib()
|
||||
}
|
||||
|
|
@ -20,5 +26,12 @@ class LabelTableViewCell: UITableViewCell {
|
|||
override func setSelected(_ selected: Bool, animated: Bool) {
|
||||
super.setSelected(selected, animated: animated)
|
||||
}
|
||||
|
||||
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
|
||||
return action == #selector(copy(_:))
|
||||
}
|
||||
override func copy(_ sender: Any?) {
|
||||
UIPasteboard.general.string = contentLabel.text
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
import UIKit
|
||||
|
||||
class PasswordDetailTableViewController: UITableViewController {
|
||||
class PasswordDetailTableViewController: UITableViewController, UIGestureRecognizerDelegate {
|
||||
var passwordEntity: PasswordEntity?
|
||||
|
||||
struct TableCell {
|
||||
|
|
@ -43,6 +43,26 @@ class PasswordDetailTableViewController: UITableViewController {
|
|||
tableData[tableDataIndex].item.append(TableCell(title: key, content: value))
|
||||
}
|
||||
}
|
||||
|
||||
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(PasswordDetailTableViewController.tapMenu(recognizer:)))
|
||||
tableView.addGestureRecognizer(tapGesture)
|
||||
tapGesture.delegate = self
|
||||
}
|
||||
|
||||
func tapMenu(recognizer: UITapGestureRecognizer) {
|
||||
print("tap")
|
||||
if recognizer.state == UIGestureRecognizerState.ended {
|
||||
let tapLocation = recognizer.location(in: self.tableView)
|
||||
if let tapIndexPath = self.tableView.indexPathForRow(at: tapLocation) {
|
||||
print(tapIndexPath)
|
||||
if let tappedCell = self.tableView.cellForRow(at: tapIndexPath) as? LabelTableViewCell {
|
||||
tappedCell.becomeFirstResponder()
|
||||
let menuController = UIMenuController.shared
|
||||
menuController.setTargetRect(tappedCell.contentLabel.frame, in: tappedCell.contentLabel.superview!)
|
||||
menuController.setMenuVisible(true, animated: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override func numberOfSections(in tableView: UITableView) -> Int {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue