Implementing Force Touch / Haptic Touch Menu for iOS
Force Touch (iPhone 6s–X) and Haptic Touch (iPhone XR and newer) are two different mechanisms, both opening context menu on long press or press with force. Since iOS 13, both technologies are unified through UIContextMenuInteraction — one implementation works on all devices.
UIContextMenuInteraction — The Right Path
UITableView and UICollectionView have built-in support through delegate methods. For arbitrary View:
let interaction = UIContextMenuInteraction(delegate: self)
myView.addInteraction(interaction)
func contextMenuInteraction(
_ interaction: UIContextMenuInteraction,
configurationForMenuAtLocation location: CGPoint
) -> UIContextMenuConfiguration? {
return UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { _ in
let share = UIAction(title: "Share", image: UIImage(systemName: "square.and.arrow.up")) { _ in
self.shareItem()
}
let delete = UIAction(title: "Delete", image: UIImage(systemName: "trash"),
attributes: .destructive) { _ in
self.deleteItem()
}
return UIMenu(title: "", children: [share, delete])
}
}
attributes: .destructive colors the item in red — standard iOS behavior for destructive actions. previewProvider — optional custom preview on long press, without it iOS shows automatic View screenshot.
For UITableView
func tableView(_ tableView: UITableView,
contextMenuConfigurationForRowAt indexPath: IndexPath,
point: CGPoint) -> UIContextMenuConfiguration? {
let item = items[indexPath.row]
return UIContextMenuConfiguration(identifier: indexPath as NSIndexPath) { [weak self] in
// Preview controller
ItemPreviewViewController(item: item)
} actionProvider: { _ in
UIMenu(title: "", children: [
UIAction(title: "Open") { _ in self?.openItem(item) },
UIAction(title: "Delete", attributes: .destructive) { _ in self?.deleteItem(item) }
])
}
}
Single implementation, works on both Force Touch and Haptic Touch, and on iPad with trackpad (right mouse button).
Timeline Benchmarks
Implementing context menu via UIContextMenuInteraction or UITableView/UICollectionView delegate methods — within one working day, including testing on devices with Force Touch and Haptic Touch.







