Skip to content

Commit

Permalink
Add a way to present popMenu from PopManager with a gesture.
Browse files Browse the repository at this point in the history
  • Loading branch information
raxityo authored and CaliCastle committed Apr 6, 2019
1 parent ab29f5a commit 64a9f61
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions PopMenu/Classes/PopMenuManager.swift
Expand Up @@ -80,7 +80,7 @@ extension PopMenuManager {
/// - sourceView: From which view and where exactly on the screen to be shown
/// (default: show in the center)
///
/// - above: Present above which controller
/// - on: Present above which controller
/// (default: use the top view controller)
///
/// - animated: Animate the presentation
Expand All @@ -98,7 +98,25 @@ extension PopMenuManager {
}
}
}


/// Present the pop menu while responding to a gesture.
///
/// - Parameters:
/// - gesture: `UIGestureRecognizer` whose location will be used to present PopMenu.
/// - on: Present above which controller
/// (default: use the top view controller)
/// - animated: Animate the presentation
/// - completion: Completion handler
public func present(with gesture: UIGestureRecognizer, on viewController: UIViewController, animated: Bool = true, completion: (() -> UIView?)? = nil) {
let sourceView = UIView(frame: CGRect(origin: gesture.location(in: nil), size: .zero))
UIApplication.shared.keyWindow?.addSubview(sourceView)

present(sourceView: sourceView, on: viewController, animated: animated) {
autoreleasepool {
sourceView.removeFromSuperview()
}
}
}
}

// MARK: - Helper Methods
Expand Down

0 comments on commit 64a9f61

Please sign in to comment.