Search code examples
objective-cswiftlong-pressuilongpressgesturerecogni

Swift Long press results


I would like to intercept the value of the long press of this pod :

https://github.com/liyong03/YLLongTapShare

enter image description here

I am developing in Swift and this pod is only Objective-C.

I don't manage to catch the func that handle the end of the selection of the long press (here, on the screenshot), I would like to retrieve "Twitter" once the user has release the long press (and his choice was Twitter)

Thanks in advance !


Solution

    1. In pod file uncomment use_frameworks! line, update pod, then build project
    2. Import 'YLLongTapShare' module in view controller
    3. Write rest of code:)

    Simple example:

    import UIKit
    import YLLongTapShare
    class TestViewController: UIViewController, YLLongTapShareDelegate {
        @IBOutlet weak var tapShareView: YLLongTapShareView!
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.tapShareView.delegate = self;
        self.tapShareView.add(YLShareItem(icon: UIImage(named: "test1"), andTitle: "test1"))
        self.tapShareView.add(YLShareItem(icon: UIImage(named: "test2"), andTitle: "test2"))
        self.tapShareView.add(YLShareItem(icon: UIImage(named: "test3"), andTitle: "test3"))
    }
    
    func longTapShare(_ view: UIView!, didSelectShareTo item: YLShareItem!, with index: UInt) {
        print("longTapShare \(item.title)")
    }
    
    func colorOfShareView() -> UIColor! {
        return UIColor.red
    }
    
    }