tap to show copy menu

This commit is contained in:
Bob Sun 2017-02-05 00:35:23 +08:00
parent 5a0b97b22f
commit 67570256d0
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
3 changed files with 38 additions and 5 deletions

View file

@ -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 {