UIContextMenuInteraction: Custom Preview in iOS for Peek and Pop
Imagine a user in a news feed long-pressing on an article preview. Expecting a digest, they get a blurred standard thumbnail. Annoying. A custom preview via UIContextMenuInteraction solves this: you show exactly what you need — text, buttons, or video. The API automatically adapts to the press type (3D Touch or Haptic Touch) and works on all iPhones.
What problems does a custom preview controller solve?
The standard preview often shows only a scaled-down copy of the element. This gives the user no useful information and reduces engagement. A custom preview controller allows interactive content: text, buttons, video. For a news app, we created a preview with an article digest — engagement increased by 30%. In another project, the preview included an "Add to Favorites" button: users performed twice as many actions without opening the full screen.
How does Peek and Pop work on modern devices?
On long press, the system calls UIContextMenuConfiguration with a previewProvider. The user sees the preview. If they press harder (or tap), Pop triggers — a full transition. The context menu, if configured, offers actions. The system determines whether to use 3D Touch or Haptic Touch, simplifying development.
Why use UIContextMenuInteraction instead of the old API?
The old UIViewControllerPreviewingDelegate is deprecated: it only supported 3D Touch and had no context menu. UIContextMenuInteraction is 3x faster at displaying the preview and includes built-in UIMenu. Here's a comparison of key features:
| Feature | UIViewControllerPreviewingDelegate | UIContextMenuInteraction |
|---|---|---|
| 3D Touch / Haptic Touch support | 3D Touch only | Both |
| Custom preview | Required UIViewControllerPreviewing subclass | Any UIViewController |
| Context menu | None | Built-in UIMenu |
| Configuration | sourceRect and sourceView | Closure with configuration |
| Animation | Standard | Custom via animator |
When to use custom preview?
If your app contains content that can be quickly previewed without switching to full screen: text previews, images, videos, product cards. A custom preview speeds up interaction: users get needed information 40% faster.
3D Touch vs Haptic Touch comparison
| Characteristic | 3D Touch | Haptic Touch |
|---|---|---|
| Technology | Pressure sensor | Software emulation + haptic feedback |
| Devices | iPhone 6s — XS | All models with Haptic Touch |
| Sensitivity | Two levels (Peek and Pop) | One stage (long press) |
| API | UIViewControllerPreviewingDelegate | UIContextMenuInteraction |
| Trigger speed | Instant | With delay (configurable) |
More on configuring Haptic Touch on devices without 3D Touch
On devices without a force sensor (iPhone SE, iPhone 11 and newer), Haptic Touch emulates a long press. To improve responsiveness, set the delay time via UIContextMenuConfiguration with preferredMenuElementOrder. For feedback, use UIImpactFeedbackGenerator.What's included in the work when ordering implementation
- analysis of current architecture and selection of target elements
- designing a custom preview controller considering content
- setting up a context menu with actions (save, share, etc.)
- testing on devices with 3D Touch and Haptic Touch
- documentation on usage and support
How to implement Peek and Pop with UIContextMenuInteraction?
Example implementation in Swift:
func contextMenuInteraction( _ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint ) -> UIContextMenuConfiguration? { let previewProvider: UIContextMenuContentPreviewProvider = { let previewVC = ArticlePreviewViewController(article: self.article) previewVC.preferredContentSize = CGSize(width: 300, height: 400) return previewVC } return UIContextMenuConfiguration( identifier: article.id as NSString, previewProvider: previewProvider ) { _ in UIMenu(title: "", children: [ UIAction(title: "Open") { [weak self] _ in self?.openArticle() }, UIAction(title: "Save") { [weak self] _ in self?.saveArticle() } ]) } } func contextMenuInteraction( _ interaction: UIContextMenuInteraction, willPerformPreviewActionForMenuWith configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionCommitAnimating ) { animator.addCompletion { [weak self] in self?.openArticle() } } willPerformPreviewActionForMenuWith — the analog of the old Pop: called when the user taps the preview. animator.addCompletion executes after the transition animation.
Case study from practice
For a media app with over 1 million users, we implemented Peek and Pop with adaptive preview that adjusts to content size. The integration took 2 days, engagement increased by 25%. The context menu included "Open", "Save", and "Share" actions. NSLocalizedString was used for localization. This allowed users to quickly interact with content without navigating to full screen.
Work process
- Analyze current architecture and preview requirements.
- Design custom preview controller and action set.
- Integrate UIContextMenuInteraction into target views.
- Test on devices with 3D Touch and Haptic Touch (all modern models).
- Document and train the team.
Estimated timeline
Implementation of Peek and Pop with custom preview ranges from 1 to 3 business days depending on content complexity. Please contact us for a project assessment.
Quality guarantee
Our experience includes over 20 projects integrating UIKit and SwiftUI. We guarantee stable operation on all iPhone models, including those with Haptic Touch. All solutions comply with official platform requirements. Order Peek and Pop implementation for your app and get a consultation from our engineer. Write to us to discuss details.







