An iOS context menu UI inspired by Things 3.

Overview

  • Contextual menus with delightful animations and styles
  • Total control over menu contents using your own UIViewControllers
  • Tons of feature and interaction customizations

Installation

Just add ContextMenu to your Podfile and pod install. Done!

pod 'ContextMenu'

For Carthage, just add GitHawkApp/ContextMenu to your Cartfile and carthage bootstrap.

github "GitHawkApp/ContextMenu"

Usage

Show the menu from one of your UIViewControllers:

ContextMenu.shared.show(
  sourceViewController: self,
  viewController: MyContentViewController()
)

You must provide a custom UIViewController to display in the menu. The only requirement is that you must set preferredContentSize to size your content.

class MyContentViewController: UIViewController {
  override func viewDidLoad() {
    super.viewDidLoad()
    title = "Demo"
    preferredContentSize = CGSize(width: 200, height: 200)
  }
}

Customizations

Display from a Source View

Animate the menu out from a button or view. ContextMenu will take care of layout so that your menu doesn't clip the screen.

@IBAction func onButton(_ sender: UIButton) {
  ContextMenu.shared.show(
    sourceViewController: self,
    viewController: MyContentViewController(),
    sourceView: sender
  )
}

Container Style & Display

Use ContextMenu.Options to change the appearance of the containing view.

ContextMenu.shared.show(
  sourceViewController: self,
  viewController: MenuViewController(),
  options: ContextMenu.Options(containerStyle: ContextMenu.ContainerStyle(backgroundColor: .blue)),
  sourceView: button
)

There's plenty more you can customize with ContextMenu.ContainerStyle:

  • cornerRadius: The corner radius of the menu
  • shadowRadius and shadowOpacity: Appearance of the container shadow
  • xPadding, yPadding, edgePadding: Padding from the source view and screen edge
  • overlayColor: The color of the background
  • motionEffect: Respond to device gyroscope changes, similar to app icons on Springboard.app.

If you want more customizations, we will gladly accept a Pull Request!

Acknowledgements

Comments
  • Run pod install on Example

    Run pod install on Example

    Example.xcworkspace is generated by pod install so there is no need to check it in. Removing this allows carthage install to work again with Swift 4.2

    If Carthage detects that there is a .workspace then it will try build that instead of ContextMenu.xcodeproj.

    opened by sbarow 10
  • Wrong present and dismiss position

    Wrong present and dismiss position

    I'm trying to use ContextMenu on rightBarButtonItem like this:

    fileprivate func setupFilterButton() {
        let button = UIButton(type: .system)
        button.addTarget(self, action: #selector(filterButtonClicked), for: .touchUpInside)
        button.setTitle("Filter", for: .normal)
        let item = UIBarButtonItem(customView: button)
            
        navigationItem.rightBarButtonItem = item
    }
    
    @objc fileprivate func filterButtonClicked() {
        let viewController = UIViewController()
        viewController.preferredContentSize = CGSize(width: 200, height: 200)
            
        ContextMenu().show(sourceViewController: self,
                           viewController: viewController,
                           sourceView: navigationItem.rightBarButtonItem?.customView,
                           delegate: nil)
    }
    

    Present worked well, but dismiss animation look like had some problem.

    And I also used it in IGListKit's method didSelectItem(at:)

    override func didSelectItem(at index: Int) {
        guard let cell = collectionContext?.cellForItem(at: index, sectionController: self) else {
            fatalError()
        }
            
        let viewController = UIViewController()
        viewController.preferredContentSize = CGSize(width: 200, height: 200)
            
        ContextMenu().show(sourceViewController: self.viewController!,
                           viewController: viewController,
                           sourceView: cell,
                           delegate: nil)
    }
    

    Both present and dismiss position weird.

    Any tips for me to fix this issue?

    ezgif-4-7d370162d8

    bug 
    opened by marcuswu0814 3
  • Unable to find a specification for `ContextMenu`

    Unable to find a specification for `ContextMenu`

    I get this when trying to install the Pod

    Unable to find a specification for 'ContextMenu'

    doing this will work however pod 'ContextMenu', git: 'https://github.com/GitHawkApp/ContextMenu.git'

    opened by mikengyn 3
  • tint-dimming behind ContentMenu

    tint-dimming behind ContentMenu

    This is a very nice implementation and I plan to use it in Working Copy for switching between branches and file modes.

    Everything behind ContextMenu is dimmed slightly with the overlay, but I'm trying to also dim the tint using the UIViewTintAdjustmentModeDimmed mechanism. This makes it much clearer that the ContextMenu has focus.

    Do you know of some way to inform UIKit that this should happen?

    A regular modalPresentationStyle = .popover gives this effect, but I cannot figure out how to achieve this with modalPresentationStyle = .custom.

    Being really picky about my development tools I'm still waiting for Swift tooling to mature and ported most of ContextMenu to objective-c. Is this something you would like to get back into the project or would you rather not?

    dim

    opened by palmin 3
  • Decrease minimum iOS version

    Decrease minimum iOS version

    Create ContextMenuHapticFeedbackStyle enumeration to mirror iOS UIImpactFeedbackGenerator.FeedbackStyle

    No changes required if shorthand calls (.light, .medium, .hard) were used. Example project compiles without any change.

    Minimum iOS version was first decreased here #35 and then it was set back to iOS 10 here #37

    opened by av0c0der 2
  • Swift 4.2

    Swift 4.2

    Updated code for Swift 4.2. I also removed the iOS 9 support for now since the project wasn't compiling since the ContextMenu+Options.swift contains UIImpactFeedbackGenerator.FeedbackStyle? which isn't available on iOS 9

    opened by batjo 1
  • Respond to keyboard

    Respond to keyboard

    Thinking about making the “new issue” UI on GitHawk use this menu, but atm the menu doesn’t respond to the keyboard showing. Imagine if you have a text box in the menu, it could get really easy to cover it up.

    I was thinking we could provide a “keyboard handling” enemy with options none, stickToBottom, stickToTop, and fit. Give the caller a bit of control.

    Sent with GitHawk

    opened by rnystrom 1
  • Ignore motion effect if reduce motion is turned on

    Ignore motion effect if reduce motion is turned on

    If a user turns on reduce motion, we should ignore the motion effects.

    If we want to keep the consumer of the library in charge, we should add a recommendation in the header docs and in the example code.

    We can also choose to ignore motion on the library level - in which case we should update the header docs to reflect it.

    good first issue 
    opened by BasThomas 1
  • Add modal escape for VoiceOver

    Add modal escape for VoiceOver

    This needs testing on a real device, as the simulator/accessibility inspector do not support testing this, so let's hold off on merging before testing this.

    Closes #30

    opened by BasThomas 0
  • Pixel blending?

    Pixel blending?

    The text in this screenshot from GitHawk looks fuzzy. Inspecting the position of the container view, it appears to be snapped appropriately, but appears to be off. Should probably just snap to a whole pixel.

    simulator screen shot - iphone xs - 2018-10-14 at 09 51 01

    screen shot 2018-10-14 at 10 26 26 am bug 
    opened by rnystrom 0
  • Set iOS 9 as min deployment target

    Set iOS 9 as min deployment target

    Seems like nothing stops us from decreasing the minimum deployment target. It has a little bug though — the navigation bar of the presented view jumps on appear. For now we didn't need the bar, so it works, whatever I'll try to investigate it later.

    opened by av0c0der 0
  • Update to 0.5.1?

    Update to 0.5.1?

    When I do pod 'ContextMenu' I get version 0.4.0. When I git clone I get version 0.5.1, which is the version in the podspec.

    I guess you updated the code but didn't update the version that Cocoapods knows about. Can you do that? Is it waiting for something?

    opened by phoney 0
  • [#44] Add API to disable tap-to-dismiss

    [#44] Add API to disable tap-to-dismiss

    Hi @rnystrom, this PR implement the #44.

    • Add a delegate method to check allow tap to dismiss. (If no delegate, default can be tap dismiss)
    • Add a delegate property for some use case, for example, when wrapped the delegate pattern to Delegate Proxy with RxSwift.

    If there have any suggestions or concerns, please let me know. 😃 Thanks.

    opened by marcuswu0814 2
  • How do I close the ContextMenu by code

    How do I close the ContextMenu by code

    Hi,

    sorry if this is a dumb question but I couldn't find a way to close the ContextMenu by code without altering the Source. Is this possible?

    Thanks!

    opened by spaggi 1
  • How can i present  two controllers on top of each other?

    How can i present two controllers on top of each other?

    i am using (0.5.1) version. i am presenting firstViewController than i am presenting my secondViewController on firstViewController. while secondViewController is being presenting, both of the controllers are disappearing. How can i fix it ?

    opened by AlicanAycil 0
Context menu similar to the one in the Pinterest iOS app

VLDContextSheet A clone of the Pinterest iOS app context menu. Example Usage VLDContextSheetItem *item1 = [[VLDContextSheetItem alloc] initWithTitle:

Vladimir Angelov 173 Mar 28, 2022
RadialMenu is a custom control for providing a touch context menu (like iMessage recording in iOS 8) built with Swift & POP

RadialMenu Looking for help? For $150/hr I'll help with your RadialMenu problems including integrating it into your project. Email [email protected] t

Brad Jasper 297 Nov 27, 2022
You can easily add awesome animated context menu to your app.

Context-Menu.iOS You can easily add awesome animated context menu to your app. Made in Check this [project on dribbble] (https://dribbble.com/shots/17

Yalantis 1.8k Nov 17, 2022
An easy way to use `canPerformAction` for context menu in SwiftUI.

Use canPerformAction for TextField/Editor in SwiftUI You know how a TextField displays a set of context menu? It doesn't matter if it's UIKit or Swift

StuFF mc 5 Dec 18, 2021
A Slide Menu, written in Swift, inspired by Slide Menu Material Design

Swift-Slide-Menu (Material Design Inspired) A Slide Menu, written in Swift 2, inspired by Navigation Drawer on Material Design (inspired by Google Mat

Boisney Philippe 90 Oct 17, 2020
PopMenu is pop animation menu inspired by Sina weibo / NetEase app.

PopMenu PopMenu is pop animation menu inspired by Sina weibo / NetEase app. Screenshots Installation CocoaPods With CocoaPods, add this line to your P

曾宪华 898 Nov 14, 2022
SwiftySideMenu is a lightweight and easy to use side menu controller to add left menu and center view controllers with scale animation based on Pop framework.

SwiftySideMenu SwiftySideMenu is a lightweight, fully customizable, and easy to use controller to add left menu and center view controllers with scale

Hossam Ghareeb 84 Feb 4, 2022
Slide-Menu - A Simple Slide Menu With Swift

Slide Menu!! Весь интерфейс создан через код

Kirill 0 Jan 8, 2022
EasyMenu - SwiftUI Menu but not only button (similar to the native Menu)

EasyMenu SwiftUI Menu but not only button (similar to the native Menu) You can c

null 10 Oct 7, 2022
Swift-sidebar-menu-example - Create amazing sidebar menu with animation using swift

 SWIFT SIDEBAR MENU EXAMPLE In this project I create a awesome side bar menu fo

Paolo Prodossimo Lopes 4 Jul 25, 2022
Hamburger Menu Button - A hamburger menu button with full customization

Hamburger Menu Button A hamburger menu button with full customization. Inspired by VinhLe's idea on the Dribble How to use it You can config the looks

Toan Nguyen 114 Jun 12, 2022
iOS Slide Menu View based on Google+, iQON, Feedly, Ameba iOS app. It is written in pure swift.

SlideMenuControllerSwift iOS Slide View based on iQON, Feedly, Google+, Ameba iPhone app. Installation CocoaPods pod 'SlideMenuControllerSwift' Carth

Yuji Hato 3.3k Dec 29, 2022
A simple side menu for iOS written in Swift.

ENSwiftSideMenu A lightweight flyover side menu component for iOS with the UIDynamic's bouncing animation, UIGestures and UIBlurEffect. Allows you to

Evgeny Nazarov 1.8k Dec 21, 2022
iOS Interactive Side Menu written in Swift.

Interactive Side Menu A customizable, interactive, auto expanding and collapsing side menu for iOS written in Swift. Here are some of the ways Interac

Handsome 706 Dec 15, 2022
A menu based on Medium iOS app.

Medium 1.8.168 menu in Swift. That is still one of my favorite menus because that is easy to use and looks beautiful.

Hiroki Nagasawa 322 May 28, 2022
A fully customizable popup style menu for iOS 😎

Guide Check out the documentation and guides for details on how to use. (Available languages:) English 简体中文 What's a better way to know what PopMenu o

Cali Castle 1.5k Dec 30, 2022
Simple side/slide menu control for iOS, no code necessary! Lots of customization. Add it to your project in 5 minutes or less.

▤ SideMenu If you like SideMenu, give it a ★ at the top right of this page. SideMenu needs your help! If you're a skilled iOS developer and want to he

Jon Kent 5.4k Dec 29, 2022
✨ Awesome Dropdown menu for iOS with Swift 5.0

The eligible dropdown menu for iOS, written in Swift 5, appears dropdown menu to display a view of related items when a user click on the dropdown menu. You can customize dropdown view whatever you like (e.g. UITableView, UICollectionView... etc)

Kyle Yi 1.3k Dec 26, 2022
iOS 7/8 style side menu with parallax effect.

RESideMenu iOS 7/8 style side menu with parallax effect inspired by Dribbble shots (first and second). Since version 4.0 you can add menu view control

Roman Efimov 7.2k Dec 28, 2022